@@ -487,8 +487,8 @@ selectClause
487487
488488projectItemDefinition
489489 : overWindowItem
490- | columnName (KW_AS ? expression)?
491490 | expression (KW_AS ? columnName)?
491+ | columnName (KW_AS ? expression)?
492492 ;
493493
494494overWindowItem
@@ -515,7 +515,11 @@ tableReference
515515tablePrimary
516516 : KW_TABLE ? tablePath systemTimePeriod?
517517 | viewPath systemTimePeriod?
518- | KW_LATERAL KW_TABLE LR_BRACKET functionName LR_BRACKET functionParam (COMMA functionParam)* RR_BRACKET RR_BRACKET
518+ | KW_LATERAL KW_TABLE LR_BRACKET (
519+ (functionNameWithParams LR_BRACKET functionParam (COMMA functionParam)* RR_BRACKET )
520+ | reservedKeywordsNoParamsUsedAsFuncName
521+ | functionNameAndParams
522+ ) RR_BRACKET
519523 | KW_LATERAL ? LR_BRACKET queryStatement RR_BRACKET
520524 | KW_UNNEST LR_BRACKET expression RR_BRACKET
521525 ;
@@ -759,15 +763,20 @@ primaryExpression
759763 | ASTERISK_SIGN # star
760764 | uid DOT ASTERISK_SIGN # star
761765 // | LR_BRACKET namedExpression (COMMA namedExpression)+ RR_BRACKET #rowConstructor
762- | LR_BRACKET queryStatement RR_BRACKET # subqueryExpression
763- | functionName LR_BRACKET (setQuantifier? functionParam (COMMA functionParam)*)? RR_BRACKET # functionCall
766+ | LR_BRACKET queryStatement RR_BRACKET # subqueryExpression
767+ | (
768+ reservedKeywordsNoParamsUsedAsFuncName
769+ | functionNameAndParams
770+ | (
771+ functionNameWithParams LR_BRACKET (setQuantifier? functionParam (COMMA functionParam)*)? RR_BRACKET
772+ )
773+ ) # functionCall
764774 // | identifier '->' expression #lambda
765775 // | '(' identifier (',' identifier)+ ')' '->' expression #lambda
766776 | value=primaryExpression LS_BRACKET index=valueExpression RS_BRACKET # subscript
767777 | identifier # columnReference
768778 | dereferenceDefinition # dereference
769779 | LR_BRACKET expression RR_BRACKET # parenthesizedExpression
770- | KW_CURRENT_TIMESTAMP # dateFunctionExpression
771780 // | EXTRACT LR_BRACKET field=identifier KW_FROM source=valueExpression RR_BRACKET #extract
772781 // | (SUBSTR | SUBSTRING) LR_BRACKET str=valueExpression (KW_FROM | COMMA) pos=valueExpression
773782 // ((KW_FOR | COMMA) len=valueExpression)? RR_BRACKET #substring
@@ -782,6 +791,25 @@ functionNameCreate
782791 ;
783792
784793functionName
794+ : reservedKeywordsUsedAsFuncName
795+ | reservedKeywordsNoParamsUsedAsFuncName
796+ | reservedKeywordsFollowParamsUsedAsFuncName
797+ | uid
798+ ;
799+
800+ /* *
801+ * Built-in function name that is following with params directly without parentheses
802+ * Reference Link:https://nightlies.apache.org/flink/flink-docs-release-1.16/zh/docs/dev/table/functions/systemfunctions/#%E6%97%B6%E9%97%B4%E5%87%BD%E6%95%B0
803+ */
804+ functionNameAndParams
805+ : reservedKeywordsFollowParamsUsedAsFuncName STRING_LITERAL
806+ | timeIntervalExpression
807+ ;
808+
809+ /* *
810+ * Function name that is need to follow with parentheses and params
811+ */
812+ functionNameWithParams
785813 : reservedKeywordsUsedAsFuncName
786814 | uid
787815 ;
@@ -1077,6 +1105,23 @@ reservedKeywordsUsedAsFuncParam
10771105 | ASTERISK_SIGN
10781106 ;
10791107
1108+ /* *
1109+ * Built-in function name without parentheses and params
1110+ */
1111+ reservedKeywordsNoParamsUsedAsFuncName
1112+ : KW_LOCALTIME
1113+ | KW_LOCALTIMESTAMP
1114+ | KW_CURRENT_TIME
1115+ | KW_CURRENT_DATE
1116+ | KW_CURRENT_TIMESTAMP
1117+ ;
1118+
1119+ reservedKeywordsFollowParamsUsedAsFuncName
1120+ : KW_DATE
1121+ | KW_TIME
1122+ | KW_TIMESTAMP
1123+ ;
1124+
10801125reservedKeywordsUsedAsFuncName
10811126 : KW_ABS
10821127 | KW_ARRAY
@@ -1089,10 +1134,6 @@ reservedKeywordsUsedAsFuncName
10891134 | KW_COLLECT
10901135 | KW_COUNT
10911136 | KW_CUME_DIST
1092- | KW_CURRENT_DATE
1093- | KW_CURRENT_TIME
1094- | KW_CURRENT_TIMESTAMP
1095- | KW_DATE
10961137 | KW_DAYOFWEEK
10971138 | KW_DAYOFYEAR
10981139 | KW_DENSE_RANK
@@ -1109,8 +1150,6 @@ reservedKeywordsUsedAsFuncName
11091150 | KW_LEAD
11101151 | KW_LEFT
11111152 | KW_LN
1112- | KW_LOCALTIME
1113- | KW_LOCALTIMESTAMP
11141153 | KW_LOWER
11151154 | KW_MAP
11161155 | KW_MAX
@@ -1135,8 +1174,6 @@ reservedKeywordsUsedAsFuncName
11351174 | KW_STDDEV_SAMP
11361175 | KW_SUBSTRING
11371176 | KW_SUM
1138- | KW_TIME
1139- | KW_TIMESTAMP
11401177 | KW_TIMESTAMP_DIFF
11411178 | KW_TRIM
11421179 | KW_TRUNCATE
0 commit comments