Skip to content

Commit fe15ad7

Browse files
Next merge main (#468)
* fix(flink): #455 fix json functions' params problem in flink * fix(flink): some grammar rules (#465) * fix: #464 order by + expression * fix: #464 EXTRACT function * test: #464 flink JSON_VALUE RETURNING * chore(release): 4.4.2 --------- Co-authored-by: zhaoge <> Co-authored-by: JackWang032 <64318393+JackWang032@users.noreply.github.com>
1 parent ff81038 commit fe15ad7

13 files changed

Lines changed: 9381 additions & 7392 deletions

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

55
## [4.5.0-beta.0](https://github.com/DTStack/dt-sql-parser/compare/v4.4.1...v4.5.0-beta.0) (2025-12-30)
6+
### [4.4.2](https://github.com/DTStack/dt-sql-parser/compare/v4.4.1...v4.4.2) (2026-03-06)
7+
8+
9+
### Bug Fixes
10+
11+
* **flink:** [#455](https://github.com/DTStack/dt-sql-parser/issues/455) fix json functions' params problem in flink ([12ef949](https://github.com/DTStack/dt-sql-parser/commit/12ef949339ffb0889e428c97c54149cd567b6ae8))
12+
* **flink:** some grammar rules ([#465](https://github.com/DTStack/dt-sql-parser/issues/465)) ([20e352c](https://github.com/DTStack/dt-sql-parser/commit/20e352cb32142c825ee086e36051ff9797798e09)), closes [#464](https://github.com/DTStack/dt-sql-parser/issues/464) [#464](https://github.com/DTStack/dt-sql-parser/issues/464) [#464](https://github.com/DTStack/dt-sql-parser/issues/464)
613

714

815
### Features

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: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,9 @@ orderByClause
685685
;
686686

687687
orderItemDefinition
688-
: columnName ordering=(KW_ASC | KW_DESC)? (KW_NULLS nullOrder=(KW_LAST | KW_FIRST))?
688+
: (columnName | valueExpression) ordering=(KW_ASC | KW_DESC)? (
689+
KW_NULLS nullOrder=(KW_LAST | KW_FIRST)
690+
)?
689691
;
690692

691693
limitClause
@@ -735,13 +737,26 @@ patternVariablesDefinition
735737

736738
windowFrame
737739
: KW_RANGE KW_BETWEEN timeIntervalExpression frameBound
740+
| (KW_ROWS | KW_RANGE) KW_BETWEEN frameStart KW_AND frameEnd
738741
| KW_ROWS KW_BETWEEN DIG_LITERAL frameBound
739742
;
740743

741744
frameBound
742745
: KW_PRECEDING KW_AND KW_CURRENT KW_ROW
743746
;
744747

748+
frameStart
749+
: KW_UNBOUNDED KW_PRECEDING
750+
| DIG_LITERAL KW_PRECEDING
751+
| KW_CURRENT KW_ROW
752+
;
753+
754+
frameEnd
755+
: KW_CURRENT KW_ROW
756+
| DIG_LITERAL KW_FOLLOWING
757+
| KW_UNBOUNDED KW_FOLLOWING
758+
;
759+
745760
withinClause
746761
: KW_WITHIN timeIntervalExpression
747762
;
@@ -774,6 +789,15 @@ predicate
774789
| KW_IS KW_JSON (KW_VALUE | KW_ARRAY | identifier)?
775790
;
776791

792+
jsonFunctionBranch
793+
: KW_NULL
794+
| KW_EMPTY KW_ARRAY
795+
| KW_EMPTY uid
796+
| KW_TRUE
797+
| KW_FALSE
798+
| KW_UNKNOWN
799+
;
800+
777801
likePredicate
778802
: KW_NOT? kind=KW_LIKE quantifier=(KW_ANY | KW_ALL) (
779803
LR_BRACKET RR_BRACKET
@@ -815,11 +839,11 @@ primaryExpression
815839
| functionCallExpression # functionCall
816840
// | identifier '->' expression #lambda
817841
// | '(' identifier (',' identifier)+ ')' '->' expression #lambda
818-
| value=primaryExpression LS_BRACKET index=valueExpression RS_BRACKET # subscript
819-
| columnNamePath # columnReference
820-
| dereferenceDefinition # dereference
821-
| LR_BRACKET expression RR_BRACKET # parenthesizedExpression
822-
// | EXTRACT LR_BRACKET field=identifier KW_FROM source=valueExpression RR_BRACKET #extract
842+
| value=primaryExpression LS_BRACKET index=valueExpression RS_BRACKET # subscript
843+
| columnNamePath # columnReference
844+
| dereferenceDefinition # dereference
845+
| LR_BRACKET expression RR_BRACKET # parenthesizedExpression
846+
| KW_EXTRACT LR_BRACKET field=identifier KW_FROM source=valueExpression RR_BRACKET # extract
823847
// | (SUBSTR | SUBSTRING) LR_BRACKET str=valueExpression (KW_FROM | COMMA) pos=valueExpression
824848
// ((KW_FOR | COMMA) len=valueExpression)? RR_BRACKET #substring
825849
// | TRIM LR_BRACKET trimOption=(BOTH | LEADING | TRAILING)? (trimStr=valueExpression)?
@@ -861,6 +885,36 @@ functionParam
861885
| timeIntervalUnit
862886
| timePointUnit
863887
| expression
888+
| jsonValueParams
889+
| jsonQueryParams
890+
| jsonObjectParams
891+
| jsonArrayParams
892+
;
893+
894+
jsonValueParams
895+
: columnNamePath (uid columnType)? (
896+
(uid | KW_NULL | KW_DEFAULT valueExpression) KW_ON KW_EMPTY
897+
)? ((uid | KW_NULL | KW_DEFAULT valueExpression) KW_ON uid)?
898+
;
899+
900+
jsonQueryParams
901+
: columnNamePath ((KW_WITHOUT | KW_WITH uid?) KW_ARRAY? uid)? (
902+
jsonFunctionBranch KW_ON KW_EMPTY
903+
)? (jsonFunctionBranch KW_ON uid)?
904+
;
905+
906+
// JSON 函数只能在 JSON_OBJECT 函数中使用
907+
jsonObjectParams
908+
: (
909+
KW_KEY? columnNamePath KW_VALUE? (
910+
valueExpression
911+
| KW_JSON LR_BRACKET (valueExpression)* RR_BRACKET
912+
)
913+
)* ((KW_NULL | uid) KW_ON KW_NULL)?
914+
;
915+
916+
jsonArrayParams
917+
: valueExpression* ((KW_NULL | uid) KW_ON KW_NULL)?
864918
;
865919

866920
dereferenceDefinition

src/lib/flink/FlinkSqlLexer.interp

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

0 commit comments

Comments
 (0)