Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feature: Added support for simple CAST #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mlilius wants to merge 1 commit into JavaScriptor:master
base: master
Choose a base branch
Loading
from mlilius:cast-support
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added support for simple casts
  • Loading branch information
mlilius committed May 20, 2020
commit 09a5275496099ccd559f1645ecb7682f2c7816c1
5 changes: 5 additions & 0 deletions src/sqlParser.jison
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ IN return 'IN'
SOUNDS return 'SOUNDS'
LIKE return 'LIKE'
ESCAPE return 'ESCAPE'
CAST return 'CAST'
REGEXP return 'REGEXP'
IS return 'IS'
UNKNOWN return 'UNKNOWN'
Expand Down Expand Up @@ -343,6 +344,9 @@ case_when_else
case_when
: CASE case_expr_opt when_then_list case_when_else END { $$ = { type: 'CaseWhen', caseExprOpt: 2,ドル whenThenList: 3,ドル else: 4ドル } }
;
cast
: CAST '(' expr AS IDENTIFIER ')' { $$ = { type: 'Cast', expr: 3,ドル castTo: 5ドル } }
;
simple_expr_prefix
: '+' simple_expr %prec UPLUS { $$ = { type: 'Prefix', prefix: 1,ドル value: 2ドル } }
| '-' simple_expr %prec UMINUS { $$ = { type: 'Prefix', prefix: 1,ドル value: 2ドル } }
Expand All @@ -361,6 +365,7 @@ simple_expr
| EXISTS '(' selectClause ')' { $$ = { type: 'SubQuery', value: 3,ドル hasExists: true } }
| '{' identifier expr '}' { $$ = { type: 'IdentifierExpr', identifier: 2,ドル value: 3ドル } }
| case_when { $$ = 1ドル }
| cast { $$ = 1ドル }
;
bit_expr
: simple_expr { $$ = 1ドル }
Expand Down
8 changes: 8 additions & 0 deletions src/stringify.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ Sql.prototype.travelCaseWhen = function(ast) {
}
this.appendKeyword('end');
};
Sql.prototype.travelCast = function(ast) {
this.appendKeyword('cast');
this.append('(', true, true);
this.travel(ast.expr);
this.appendKeyword('as');
this.append(ast.castTo);
this.append(')', true);
};
Sql.prototype.travelPrefix = function(ast) {
this.appendKeyword(ast.prefix);
this.travel(ast.value);
Expand Down
15 changes: 15 additions & 0 deletions test/main.test.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,19 @@ describe('select grammar support', function() {
it('bugfix table alias2', function() {
testParser('select a.* from a t1 join b t2 on t1.a = t2.a')
})

it('CAST support issue #9', function() {
testParser(`select
concat(dsw_cluster_name,',',logic_pod_name) as event_obj,
concat(dsw_cluster_name,',',logic_pod_name, ' PFC STORM. 详情: ',
'流量突跃 ', cast(FLOW_RX_BPS_RATE100 as int), '%(RX)',
'; ', cast(FLOW_TX_BPS_RATE100 as int), '%(TX)',
'; PFC 突增 ', cast(PFC_RX_PPS_RATE*100 as int), '%(RECV)') as brief
from SOURCE_BASIC_EVENT_POD_FLOW_AND_PFC_TREND
where win_end >= '2020年05月19日 21:14:12'
and win_end < '2020年05月20日 21:14:12'
and PFC_RX_PPS_RATE >= 100
and (FLOW_RX_BPS_RATE <= -0.2 and FLOW_TX_BPS_RATE <= -0.2)
`)
})
});

AltStyle によって変換されたページ (->オリジナル) /