Skip to content

Commit 893a35c

Browse files
author
zhaoge
committed
fix(flink): #455 fix json functions' params problem in flink
1 parent f65a451 commit 893a35c

File tree

6 files changed

+4248
-2761
lines changed

6 files changed

+4248
-2761
lines changed

src/grammar/flink/FlinkSqlParser.g4

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,15 @@ predicate
738738
| KW_IS KW_JSON (KW_VALUE | KW_ARRAY | identifier)?
739739
;
740740

741+
jsonFunctionBranch
742+
: KW_NULL
743+
| KW_EMPTY KW_ARRAY
744+
| KW_EMPTY uid
745+
| KW_TRUE
746+
| KW_FALSE
747+
| KW_UNKNOWN
748+
;
749+
741750
likePredicate
742751
: KW_NOT? kind=KW_LIKE quantifier=(KW_ANY | KW_ALL) (
743752
LR_BRACKET RR_BRACKET
@@ -761,6 +770,8 @@ functionCallExpression
761770
: reservedKeywordsNoParamsUsedAsFuncName
762771
| functionNameAndParams
763772
| functionNameWithParams LR_BRACKET (setQuantifier? functionParam (COMMA functionParam)*)? RR_BRACKET
773+
| KW_JSON_ARRAY LR_BRACKET (jsonArrayParams (COMMA jsonArrayParams)*)? RR_BRACKET
774+
| KW_JSON_OBJECT LR_BRACKET (jsonObjectParams (COMMA jsonObjectParams)*)? RR_BRACKET
764775
;
765776

766777
primaryExpression
@@ -824,7 +835,34 @@ functionParam
824835
: reservedKeywordsUsedAsFuncParam
825836
| timeIntervalUnit
826837
| timePointUnit
827-
| expression
838+
| jsonValueParams
839+
| jsonQueryParams
840+
;
841+
842+
jsonValueParams
843+
: expression (columnNamePath columnType)? (
844+
(uid | KW_NULL | KW_DEFAULT valueExpression) KW_ON KW_EMPTY
845+
)? ((uid | KW_NULL | KW_DEFAULT valueExpression) KW_ON uid)?
846+
;
847+
848+
jsonQueryParams
849+
: expression columnNamePath? ((KW_WITHOUT | KW_WITH uid?) KW_ARRAY? uid)? (
850+
jsonFunctionBranch KW_ON KW_EMPTY
851+
)? (jsonFunctionBranch KW_ON uid)?
852+
;
853+
854+
// JSON 函数只能在 JSON_OBJECT 函数中使用
855+
jsonObjectParams
856+
: (
857+
KW_KEY? columnNamePath KW_VALUE? (
858+
valueExpression
859+
| KW_JSON LR_BRACKET (valueExpression)* RR_BRACKET
860+
)
861+
)* ((KW_NULL | uid) KW_ON KW_NULL)?
862+
;
863+
864+
jsonArrayParams
865+
: valueExpression* ((KW_NULL | uid) KW_ON KW_NULL)?
828866
;
829867

830868
dereferenceDefinition

src/lib/flink/FlinkSqlParser.interp

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

0 commit comments

Comments
 (0)