Skip to content

Commit dd565a2

Browse files
committed
fix: #464 order by + expression
1 parent 9dc6cfc commit dd565a2

11 files changed

Lines changed: 7710 additions & 7340 deletions

File tree

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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ projectItemDefinition
496496
;
497497

498498
overWindowItem
499-
: primaryExpression KW_OVER windowSpec KW_AS identifier
500-
| primaryExpression KW_OVER errorCapturingIdentifier KW_AS identifier
499+
: primaryExpression KW_OVER windowSpec (KW_AS identifier)?
500+
| primaryExpression KW_OVER errorCapturingIdentifier (KW_AS identifier)?
501501
;
502502

503503
fromClause
@@ -644,7 +644,9 @@ orderByClause
644644
;
645645

646646
orderItemDefinition
647-
: columnName ordering=(KW_ASC | KW_DESC)? (KW_NULLS nullOrder=(KW_LAST | KW_FIRST))?
647+
: (columnName | valueExpression) ordering=(KW_ASC | KW_DESC)? (
648+
KW_NULLS nullOrder=(KW_LAST | KW_FIRST)
649+
)?
648650
;
649651

650652
limitClause
@@ -694,13 +696,26 @@ patternVariablesDefinition
694696

695697
windowFrame
696698
: KW_RANGE KW_BETWEEN timeIntervalExpression frameBound
699+
| (KW_ROWS | KW_RANGE) KW_BETWEEN frameStart KW_AND frameEnd
697700
| KW_ROWS KW_BETWEEN DIG_LITERAL frameBound
698701
;
699702

700703
frameBound
701704
: KW_PRECEDING KW_AND KW_CURRENT KW_ROW
702705
;
703706

707+
frameStart
708+
: KW_UNBOUNDED KW_PRECEDING
709+
| DIG_LITERAL KW_PRECEDING
710+
| KW_CURRENT KW_ROW
711+
;
712+
713+
frameEnd
714+
: KW_CURRENT KW_ROW
715+
| DIG_LITERAL KW_FOLLOWING
716+
| KW_UNBOUNDED KW_FOLLOWING
717+
;
718+
704719
withinClause
705720
: KW_WITHIN timeIntervalExpression
706721
;

src/lib/flink/FlinkSqlLexer.interp

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

0 commit comments

Comments
 (0)