@@ -175,7 +175,6 @@ lengthTwoStringDimension
175175
176176lengthOneTypeDimension
177177 : LESS_SYMBOL columnType (COMMA columnType)* GREATER_SYMBOL #lengthSymbolsTypeDimension
178- | LS_BRACKET columnType (COMMA columnType)* RS_BRACKET #lengthBracketTypeDimension
179178 ;
180179
181180mapTypeDimension
@@ -184,7 +183,6 @@ mapTypeDimension
184183
185184rowTypeDimension
186185 : LESS_SYMBOL columnName columnType (COMMA columnName columnType)* GREATER_SYMBOL #rowSymbolsTypeDimension
187- | LS_BRACKET columnName columnType (COMMA columnName columnType)* RS_BRACKET #rowBracketTypeDimension
188186 ;
189187
190188columnConstraint
@@ -418,7 +416,7 @@ selectStatement
418416 ;
419417
420418selectClause
421- : KW_SELECT setQuantifier? (ASTERISK_SIGN | projectItemDefinition (COMMA projectItemDefinition)*)
419+ : KW_SELECT setQuantifier? (ASTERISK_SIGN | projectItemDefinition (COMMA projectItemDefinition)*)
422420 ;
423421
424422projectItemDefinition
@@ -704,24 +702,26 @@ valueExpression
704702primaryExpression
705703 : KW_CASE whenClause+ (KW_ELSE elseExpression=expression)? KW_END #searchedCase
706704 | KW_CASE value=expression whenClause+ (KW_ELSE elseExpression=expression)? KW_END #simpleCase
707- | KW_CAST ' ( ' expression KW_AS columnType ' ) ' #cast
705+ | KW_CAST LR_BRACKET expression KW_AS columnType RR_BRACKET #cast
708706 // | STRUCT '(' (argument+=namedExpression (',' argument+=namedExpression)*)? ')' #struct
709- | KW_FIRST ' ( ' expression (KW_IGNORE KW_NULLS )? ' ) ' #first
710- | KW_LAST ' ( ' expression (KW_IGNORE KW_NULLS )? ' ) ' #last
711- | KW_POSITION ' ( ' substr=valueExpression KW_IN str=valueExpression ' ) ' #position
707+ | KW_FIRST LR_BRACKET expression (KW_IGNORE KW_NULLS )? RR_BRACKET #first
708+ | KW_LAST LR_BRACKET expression (KW_IGNORE KW_NULLS )? RR_BRACKET #last
709+ | KW_POSITION LR_BRACKET substr=valueExpression KW_IN str=valueExpression RR_BRACKET #position
712710 | constant #constantDefault
713711 | ' *' #star
714712 | uid ' .' ' *' #star
715713 // | '(' namedExpression (',' namedExpression)+ ')' #rowConstructor
716- | ' (' queryStatement ' )' #subqueryExpression
717- | functionName ' (' (setQuantifier? functionParam (' ,' functionParam)*)? ' )' #functionCall
718- | functionName ' (' functionParam KW_TO functionParam ' )' #functionCall
714+ | LR_BRACKET queryStatement RR_BRACKET #subqueryExpression
715+ | functionName LR_BRACKET (setQuantifier? functionParam (' ,' functionParam)*)? RR_BRACKET #functionCall
716+ | functionName LR_BRACKET functionParam KW_TO functionParam RR_BRACKET #functionCall
717+ | functionName LR_BRACKET setQuantifier? functionParam RR_BRACKET filterClause? #functionCallFilter
719718 // | identifier '->' expression #lambda
720719 // | '(' identifier (',' identifier)+ ')' '->' expression #lambda
721720 | value=primaryExpression LS_BRACKET index=valueExpression RS_BRACKET #subscript
722721 | identifier #columnReference
723722 | dereferenceDefinition #dereference
724- | ' (' expression ' )' #parenthesizedExpression
723+ | LR_BRACKET expression RR_BRACKET #parenthesizedExpression
724+ | complexDataTypeExpression # complexDataTypeFieldExpression
725725 // | EXTRACT '(' field=identifier KW_FROM source=valueExpression ')' #extract
726726 // | (SUBSTR | SUBSTRING) '(' str=valueExpression (KW_FROM | ',') pos=valueExpression
727727 // ((KW_FOR | ',') len=valueExpression)? ')' #substring
@@ -731,6 +731,36 @@ primaryExpression
731731 // KW_FROM position=valueExpression (KW_FOR length=valueExpression)? ')' #overlay
732732 ;
733733
734+
735+
736+
737+ complexDataTypeExpression
738+ : arrayExpression
739+ | rowExpression
740+ | mapExpression
741+ ;
742+
743+ arrayExpression
744+ : KW_ARRAY LS_BRACKET dataTypeExpression RS_BRACKET
745+ ;
746+
747+ rowExpression
748+ : KW_ROW LR_BRACKET rowFieldExpression (COMMA rowFieldExpression)* RR_BRACKET
749+ ;
750+
751+ mapExpression
752+ : KW_MAP LS_BRACKET dataTypeExpression COMMA dataTypeExpression RS_BRACKET
753+ ;
754+
755+ rowFieldExpression
756+ : dataTypeExpression KW_AS identifier
757+ ;
758+
759+ dataTypeExpression
760+ : columnAlias
761+ | complexDataTypeExpression
762+ ;
763+
734764functionName
735765 : reservedKeywordsUsedAsFuncName
736766 | nonReservedKeywords
@@ -742,6 +772,11 @@ functionParam
742772 | timeIntervalUnit
743773 | timePointUnit
744774 | expression
775+ | filterClause
776+ ;
777+
778+ filterClause
779+ : KW_FILTER LR_BRACKET KW_WHERE booleanExpression RR_BRACKET
745780 ;
746781
747782dereferenceDefinition
@@ -1470,6 +1505,7 @@ KW_EXCEPTION: E X C E P T I O N;
14701505KW_EXCLUDE : E X C L U D E ;
14711506KW_EXCLUDING : E X C L U D I N G ;
14721507KW_EXTENDED : E X T E N D E D ;
1508+ KW_FILTER : F I L T E R ;
14731509KW_FILE : F I L E ;
14741510KW_FINAL : F I N A L ;
14751511KW_FIRST : F I R S T ;
0 commit comments