@@ -186,6 +186,21 @@ statement
186186 KW_USING indexType=identifier
187187 )? LEFT_PAREN multipartIdentifierPropertyList RIGHT_PAREN (KW_OPTIONS options=propertyList)? # createIndex
188188 | KW_DROP KW_INDEX (ifExists)? identifier KW_ON KW_TABLE? tableName # dropIndex
189+ | KW_CALL functionName LEFT_PAREN (functionArgument (COMMA functionArgument)*)? RIGHT_PAREN # callStatement
190+ | KW_ALTER KW_TABLE icebergTableName KW_ADD KW_PARTITION KW_FIELD transform (
191+ KW_AS name=identifier
192+ )? # addPartitionField
193+ | KW_ALTER KW_TABLE icebergTableName KW_DROP KW_PARTITION KW_FIELD transform # dropPartitionField
194+ | KW_ALTER KW_TABLE icebergTableName KW_REPLACE KW_PARTITION KW_FIELD transform KW_WITH transform (
195+ KW_AS name=identifier
196+ )? # replacePartitionField
197+ | KW_ALTER KW_TABLE icebergTableName KW_WRITE icebergWriteSpec # setWriteDistributionAndOrdering
198+ | KW_ALTER KW_TABLE icebergTableName KW_SET KW_IDENTIFIER KW_FIELDS multipartIdentifierList # setIdentifierFields
199+ | KW_ALTER KW_TABLE icebergTableName KW_DROP KW_IDENTIFIER KW_FIELDS multipartIdentifierList # dropIdentifierFields
200+ | KW_ALTER KW_TABLE icebergTableName icebergCreateReplaceBranchClause # createOrReplaceBranch
201+ | KW_ALTER KW_TABLE icebergTableName icebergCreateReplaceTagClause # createOrReplaceTag
202+ | KW_ALTER KW_TABLE icebergTableName KW_DROP KW_BRANCH ifExists? identifier # dropBranch
203+ | KW_ALTER KW_TABLE icebergTableName KW_DROP KW_TAG ifExists? identifier # dropTag
189204 | KW_OPTIMIZE tableName whereClause? zOrderClause # optimizeTable
190205 | unsupportedHiveNativeCommands .*? # unsupportHiveCommands
191206 ;
@@ -250,15 +265,14 @@ query
250265 ;
251266
252267insertInto
253- : KW_INSERT KW_OVERWRITE KW_TABLE? tableName (partitionSpec (ifNotExists)?)? (
268+ : KW_INSERT KW_OVERWRITE KW_TABLE? icebergTableName (partitionSpec (ifNotExists)?)? (
254269 (KW_BY KW_NAME)
255270 | (LEFT_PAREN columnNameSeq RIGHT_PAREN)
256271 )?
257- | KW_INSERT KW_INTO KW_TABLE? tableName partitionSpec? (ifNotExists)? (
272+ | KW_INSERT KW_INTO KW_TABLE? icebergTableName partitionSpec? (ifNotExists)? (
258273 (KW_BY KW_NAME)
259274 | (LEFT_PAREN columnNameSeq RIGHT_PAREN)
260- )?
261- | KW_INSERT KW_INTO KW_TABLE? tableName KW_REPLACE whereClause
275+ )? (KW_REPLACE whereClause)?
262276 | KW_INSERT KW_OVERWRITE KW_LOCAL? KW_DIRECTORY path=stringLit rowFormat? createFileFormat?
263277 | KW_INSERT KW_OVERWRITE KW_LOCAL? KW_DIRECTORY (path=stringLit)? tableProvider (
264278 KW_OPTIONS options=propertyList
@@ -379,12 +393,12 @@ storageHandler
379393 ;
380394
381395dmlStatementNoWith
382- : insertInto query # insertFromQuery
383- | fromClause (insertInto fromStatementBody)+ # multipleInsert
384- | KW_DELETE KW_FROM tableName tableAlias whereClause? # deleteFromTable
385- | KW_UPDATE tableName tableAlias setClause whereClause? # updateTable
386- | KW_MERGE KW_INTO target=tableName targetAlias=tableAlias KW_USING (
387- source=identifierReference
396+ : insertInto query # insertFromQuery
397+ | fromClause (insertInto fromStatementBody)+ # multipleInsert
398+ | KW_DELETE KW_FROM icebergTableName tableAlias whereClause? # deleteFromTable
399+ | KW_UPDATE icebergTableName tableAlias setClause whereClause? # updateTable
400+ | KW_MERGE KW_INTO target=icebergTableName targetAlias=tableAlias KW_USING (
401+ source=icebergTableName
388402 | LEFT_PAREN sourceQuery=query RIGHT_PAREN
389403 ) sourceAlias=tableAlias KW_ON mergeCondition=booleanExpression matchedClause* notMatchedClause* notMatchedBySourceClause* # mergeIntoTable
390404 ;
@@ -405,6 +419,10 @@ tableName
405419 : tableIdentifier
406420 ;
407421
422+ icebergTableName
423+ : tableIdentifier
424+ ;
425+
408426viewNameCreate
409427 : viewIdentifier
410428 ;
@@ -439,6 +457,10 @@ columnNameCreate
439457 : errorCapturingIdentifier
440458 ;
441459
460+ nestedColumnNameCreate
461+ : multipartIdentifier
462+ ;
463+
442464identifierReference
443465 : KW_IDENTIFIER LEFT_PAREN expression RIGHT_PAREN
444466 | multipartIdentifier
@@ -732,11 +754,11 @@ identifierComment
732754 ;
733755
734756relationPrimary
735- : (tableName | viewName | identifierReference ) temporalClause? sample? tableAlias # tableSource
736- | atomSubQueryTableSource sample? tableAlias # subQueryTableSource
737- | LEFT_PAREN relation RIGHT_PAREN sample? tableAlias # joinTableSource
738- | inlineTable tableAlias # inlineTableSource
739- | functionTable # functionTableSource
757+ : (tableName | viewName | tableIdentifierReference ) temporalClause? sample? tableAlias # tableSource
758+ | atomSubQueryTableSource sample? tableAlias # subQueryTableSource
759+ | LEFT_PAREN relation RIGHT_PAREN sample? tableAlias # joinTableSource
760+ | inlineTable tableAlias # inlineTableSource
761+ | functionTable # functionTableSource
740762 ;
741763
742764atomSubQueryTableSource
@@ -825,12 +847,23 @@ multipartIdentifierProperty
825847 : multipartIdentifier (KW_OPTIONS options =propertyList)?
826848 ;
827849
850+ boundedQualifiedIdentifier
851+ : parts+=errorCapturingIdentifier DOT parts+=errorCapturingIdentifier DOT parts+=errorCapturingIdentifier DOT parts+=errorCapturingIdentifier
852+ ;
853+
828854tableIdentifier
829- : (db=errorCapturingIdentifier DOT)? table=errorCapturingIdentifier
855+ : (catalog=errorCapturingIdentifier DOT)? (db=errorCapturingIdentifier DOT)? table=errorCapturingIdentifier
856+ | boundedQualifiedIdentifier
830857 ;
831858
832859viewIdentifier
833- : (db=errorCapturingIdentifier DOT)? view=errorCapturingIdentifier
860+ : (catalog=errorCapturingIdentifier DOT)? (db=errorCapturingIdentifier DOT)? view=errorCapturingIdentifier
861+ | boundedQualifiedIdentifier
862+ ;
863+
864+ tableIdentifierReference
865+ : KW_IDENTIFIER LEFT_PAREN expression RIGHT_PAREN
866+ | tableIdentifier
834867 ;
835868
836869selectLiteralColumnName
@@ -879,6 +912,71 @@ transformArgument
879912 | constant
880913 ;
881914
915+ icebergWriteSpec
916+ : (icebergWriteDistributionSpec | icebergWriteOrderingSpec)+
917+ ;
918+
919+ icebergWriteDistributionSpec
920+ : KW_DISTRIBUTED KW_BY KW_PARTITION
921+ ;
922+
923+ icebergWriteOrderingSpec
924+ : KW_LOCALLY ? KW_ORDERED KW_BY icebergOrder
925+ | KW_UNORDERED
926+ ;
927+
928+ icebergOrder
929+ : icebergOrderField (COMMA icebergOrderField)*
930+ | LEFT_PAREN icebergOrderField (COMMA icebergOrderField)* RIGHT_PAREN
931+ ;
932+
933+ icebergOrderField
934+ : transform direction=(KW_ASC | KW_DESC )? (KW_NULLS nullOrder=(KW_FIRST | KW_LAST ))?
935+ ;
936+
937+ icebergCreateReplaceBranchClause
938+ : (KW_CREATE KW_OR )? KW_REPLACE KW_BRANCH identifier icebergBranchOptions
939+ | KW_CREATE KW_BRANCH ifNotExists? identifier icebergBranchOptions
940+ ;
941+
942+ icebergCreateReplaceTagClause
943+ : (KW_CREATE KW_OR )? KW_REPLACE KW_TAG identifier icebergTagOptions
944+ | KW_CREATE KW_TAG ifNotExists? identifier icebergTagOptions
945+ ;
946+
947+ icebergBranchOptions
948+ : (KW_AS KW_OF KW_VERSION snapshotId=number)? icebergRefRetain? icebergSnapshotRetention?
949+ ;
950+
951+ icebergTagOptions
952+ : (KW_AS KW_OF KW_VERSION snapshotId=number)? icebergRefRetain?
953+ ;
954+
955+ icebergSnapshotRetention
956+ : KW_WITH KW_SNAPSHOT KW_RETENTION (
957+ icebergMinSnapshotsToKeep icebergMaxSnapshotAge?
958+ | icebergMaxSnapshotAge
959+ )
960+ ;
961+
962+ icebergRefRetain
963+ : KW_RETAIN number icebergTimeUnit
964+ ;
965+
966+ icebergMaxSnapshotAge
967+ : number icebergTimeUnit
968+ ;
969+
970+ icebergMinSnapshotsToKeep
971+ : number KW_SNAPSHOTS
972+ ;
973+
974+ icebergTimeUnit
975+ : KW_DAYS
976+ | KW_HOURS
977+ | KW_MINUTES
978+ ;
979+
882980expression
883981 : booleanExpression
884982 ;
@@ -1161,7 +1259,7 @@ qualifiedColTypeWithPositionSeqForAdd
11611259 ;
11621260
11631261qualifiedColTypeWithPositionForAdd
1164- : name=columnNameCreate dataType colDefinitionDescriptorWithPosition*
1262+ : name=nestedColumnNameCreate dataType colDefinitionDescriptorWithPosition*
11651263 ;
11661264
11671265qualifiedColTypeWithPositionSeqForReplace
@@ -1317,7 +1415,7 @@ number
13171415 ;
13181416
13191417alterColumnAction
1320- : KW_TYPE dataType
1418+ : KW_TYPE dataType ( KW_COMMENT comment=stringLit)?
13211419 | KW_COMMENT comment=stringLit
13221420 | colPosition
13231421 | setOrDrop=(KW_SET | KW_DROP ) KW_NOT KW_NULL
@@ -1664,11 +1762,13 @@ nonReserved
16641762 | KW_BINARY_HEX
16651763 | KW_BOOLEAN
16661764 | KW_BOTH
1765+ | KW_BRANCH
16671766 | KW_BUCKET
16681767 | KW_BUCKETS
16691768 | KW_BY
16701769 | KW_BYTE
16711770 | KW_CACHE
1771+ | KW_CALL
16721772 | KW_CASCADE
16731773 | KW_CASE
16741774 | KW_CAST
@@ -1728,6 +1828,7 @@ nonReserved
17281828 | KW_DISABLE
17291829 | KW_DISTINCT
17301830 | KW_DISTRIBUTE
1831+ | KW_DISTRIBUTED
17311832 | KW_DIV
17321833 | KW_DOUBLE
17331834 | KW_DROP
@@ -1746,6 +1847,7 @@ nonReserved
17461847 | KW_EXTRACT
17471848 | KW_FALSE
17481849 | KW_FETCH
1850+ | KW_FIELD
17491851 | KW_FILTER
17501852 | KW_FIELDS
17511853 | KW_FILEFORMAT
@@ -1797,6 +1899,7 @@ nonReserved
17971899 | KW_LIST
17981900 | KW_LOAD
17991901 | KW_LOCAL
1902+ | KW_LOCALLY
18001903 | KW_LOCATION
18011904 | KW_LOCK
18021905 | KW_LOCKS
@@ -1834,6 +1937,7 @@ nonReserved
18341937 | KW_OPTIONS
18351938 | KW_OR
18361939 | KW_ORDER
1940+ | KW_ORDERED
18371941 | KW_OUT
18381942 | KW_OUTER
18391943 | KW_OUTPUTFORMAT
@@ -1872,6 +1976,8 @@ nonReserved
18721976 | KW_RESET
18731977 | KW_RESPECT
18741978 | KW_RESTRICT
1979+ | KW_RETAIN
1980+ | KW_RETENTION
18751981 | KW_REVOKE
18761982 | KW_REWRITE
18771983 | KW_RLIKE
@@ -1896,6 +2002,8 @@ nonReserved
18962002 | KW_SHOW
18972003 | KW_SINGLE
18982004 | KW_SKEWED
2005+ | KW_SNAPSHOT
2006+ | KW_SNAPSHOTS
18992007 | KW_SMALLINT
19002008 | KW_SOME
19012009 | KW_SORT
@@ -1913,7 +2021,8 @@ nonReserved
19132021 | KW_SYSTEM
19142022 | KW_SYSTEM_TIME
19152023 | KW_SYSTEM_VERSION
1916- // | KW_TABLE
2024+ | KW_TAG
2025+ | KW_TABLE
19172026 | KW_TABLES
19182027 | KW_TABLESAMPLE
19192028 | KW_TARGET
@@ -1946,6 +2055,7 @@ nonReserved
19462055 | KW_UNIQUE
19472056 | KW_UNKNOWN
19482057 | KW_UNLOCK
2058+ | KW_UNORDERED
19492059 | KW_UNPIVOT
19502060 | KW_UNSET
19512061 | KW_UPDATE
@@ -1966,6 +2076,7 @@ nonReserved
19662076 | KW_WINDOW
19672077 | KW_WITH
19682078 | KW_WITHIN
2079+ | KW_WRITE
19692080 | KW_YEAR
19702081 | KW_YEARS
19712082 | KW_ZONE
0 commit comments