Movatterモバイル変換


[0]ホーム

URL:


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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mlilius wants to merge1 commit intoJavaScriptor:master
base:master
Choose a base branch
Loading
frommlilius:cast-support
Open
Show file tree
Hide file tree
Changes fromall 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
5 changes: 5 additions & 0 deletionssrc/sqlParser.jison
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 deletionssrc/stringify.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionstest/main.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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)
`)
})
});

[8]ページ先頭

©2009-2025 Movatter.jp