Skip to content

Commit 20e352c

Browse files
authored
fix(flink): some grammar rules (#465)
* fix: #464 order by + expression * fix: #464 EXTRACT function * test: #464 flink JSON_VALUE RETURNING
1 parent fbcc9bf commit 20e352c

File tree

12 files changed

+7920
-7473
lines changed

12 files changed

+7920
-7473
lines changed

src/grammar/flink/FlinkSqlLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ KW_FILTER : 'FILTER';
171171
KW_FIRST_VALUE : 'FIRST_VALUE';
172172
KW_FLOAT : 'FLOAT';
173173
KW_FLOOR : 'FLOOR';
174+
KW_FOLLOWING : 'FOLLOWING';
174175
KW_FOR : 'FOR';
175176
KW_FOREIGN : 'FOREIGN';
176177
KW_FRAME_ROW : 'FRAME_ROW';
@@ -428,6 +429,7 @@ KW_TRUNCATE : 'TRUNCATE';
428429
KW_TRY_CAST : 'TRY_CAST';
429430
KW_TUESDAY : 'TUESDAY';
430431
KW_UESCAPE : 'UESCAPE';
432+
KW_UNBOUNDED : 'UNBOUNDED';
431433
KW_UNION : 'UNION';
432434
KW_UNIQUE : 'UNIQUE';
433435
KW_UNKNOWN : 'UNKNOWN';

src/grammar/flink/FlinkSqlParser.g4

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,9 @@ orderByClause
649649
;
650650

651651
orderItemDefinition
652-
: columnName ordering=(KW_ASC | KW_DESC)? (KW_NULLS nullOrder=(KW_LAST | KW_FIRST))?
652+
: (columnName | valueExpression) ordering=(KW_ASC | KW_DESC)? (
653+
KW_NULLS nullOrder=(KW_LAST | KW_FIRST)
654+
)?
653655
;
654656

655657
limitClause
@@ -699,13 +701,26 @@ patternVariablesDefinition
699701

700702
windowFrame
701703
: KW_RANGE KW_BETWEEN timeIntervalExpression frameBound
704+
| (KW_ROWS | KW_RANGE) KW_BETWEEN frameStart KW_AND frameEnd
702705
| KW_ROWS KW_BETWEEN DIG_LITERAL frameBound
703706
;
704707

705708
frameBound
706709
: KW_PRECEDING KW_AND KW_CURRENT KW_ROW
707710
;
708711

712+
frameStart
713+
: KW_UNBOUNDED KW_PRECEDING
714+
| DIG_LITERAL KW_PRECEDING
715+
| KW_CURRENT KW_ROW
716+
;
717+
718+
frameEnd
719+
: KW_CURRENT KW_ROW
720+
| DIG_LITERAL KW_FOLLOWING
721+
| KW_UNBOUNDED KW_FOLLOWING
722+
;
723+
709724
withinClause
710725
: KW_WITHIN timeIntervalExpression
711726
;
@@ -788,11 +803,11 @@ primaryExpression
788803
| functionCallExpression # functionCall
789804
// | identifier '->' expression #lambda
790805
// | '(' identifier (',' identifier)+ ')' '->' expression #lambda
791-
| value=primaryExpression LS_BRACKET index=valueExpression RS_BRACKET # subscript
792-
| columnNamePath # columnReference
793-
| dereferenceDefinition # dereference
794-
| LR_BRACKET expression RR_BRACKET # parenthesizedExpression
795-
// | EXTRACT LR_BRACKET field=identifier KW_FROM source=valueExpression RR_BRACKET #extract
806+
| value=primaryExpression LS_BRACKET index=valueExpression RS_BRACKET # subscript
807+
| columnNamePath # columnReference
808+
| dereferenceDefinition # dereference
809+
| LR_BRACKET expression RR_BRACKET # parenthesizedExpression
810+
| KW_EXTRACT LR_BRACKET field=identifier KW_FROM source=valueExpression RR_BRACKET # extract
796811
// | (SUBSTR | SUBSTRING) LR_BRACKET str=valueExpression (KW_FROM | COMMA) pos=valueExpression
797812
// ((KW_FOR | COMMA) len=valueExpression)? RR_BRACKET #substring
798813
// | TRIM LR_BRACKET trimOption=(BOTH | LEADING | TRAILING)? (trimStr=valueExpression)?

src/lib/flink/FlinkSqlLexer.interp

Lines changed: 7 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)