Skip to content

Commit b957f6d

Browse files
committed
refactor: optimize impalasql grammar
1 parent 1e853da commit b957f6d

6 files changed

Lines changed: 3344 additions & 3630 deletions

File tree

src/grammar/impala/ImpalaSqlParser.g4

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ createKuduTableAsSelect
9696
: KW_CREATE KW_EXTERNAL? KW_TABLE ifNotExists? tableNameCreate (
9797
LPAREN kuduTableElement (COMMA kuduTableElement)* (COMMA KW_PRIMARY KW_KEY columnAliases)? RPAREN
9898
)? (KW_PRIMARY KW_KEY columnAliases?)? (KW_PARTITION KW_BY kuduPartitionClause)? (
99-
commentClause
99+
KW_COMMENT comment=stringLiteral
100100
)? KW_STORED KW_AS KW_KUDU (KW_TBLPROPERTIES tblProp=properties)? (KW_AS queryStatement)?
101101
;
102102

@@ -156,8 +156,13 @@ alterDatabase
156156
;
157157

158158
alterStatsKey
159-
: KW_ALTER KW_TABLE tableNamePath KW_SET KW_COLUMN KW_STATS columnNamePath LPAREN statsKey EQ stringLiteral (
160-
COMMA statsKey EQ stringLiteral
159+
: KW_ALTER KW_TABLE tableNamePath KW_SET KW_COLUMN KW_STATS columnNamePath LPAREN (
160+
STATS_NUMDVS
161+
| STATS_NUMNULLS
162+
| STATS_AVGSIZE
163+
| STATS_MAXSIZE
164+
) EQ stringLiteral (
165+
COMMA (STATS_NUMDVS | STATS_NUMNULLS | STATS_AVGSIZE | STATS_MAXSIZE) EQ stringLiteral
161166
)? RPAREN
162167
;
163168

@@ -670,13 +675,6 @@ kuduStorageAttr
670675
| KW_BLOCK_SIZE number
671676
;
672677

673-
statsKey
674-
: STATS_NUMDVS
675-
| STATS_NUMNULLS
676-
| STATS_AVGSIZE
677-
| STATS_MAXSIZE
678-
;
679-
680678
fileFormat
681679
: KW_TEXTFILE
682680
| KW_PARQUET
@@ -870,17 +868,12 @@ joinCriteria
870868

871869
sampledRelation
872870
: aliasedRelation (
873-
KW_TABLESAMPLE sampleType LPAREN percentage=expression RPAREN (
871+
KW_TABLESAMPLE (KW_BERNOULLI | KW_SYSTEM) LPAREN percentage=expression RPAREN (
874872
KW_REPEATABLE LPAREN seed=expression RPAREN
875873
)?
876874
)?
877875
;
878876

879-
sampleType
880-
: KW_BERNOULLI
881-
| KW_SYSTEM
882-
;
883-
884877
aliasedRelation
885878
: relationPrimary (KW_AS? alias=identifier columnAliases?)?
886879
;
@@ -962,7 +955,7 @@ primaryExpression
962955
| identifier stringLiteral # typeConstructor
963956
| DOUBLE_PRECISION stringLiteral # typeConstructor
964957
| number # numericLiteral
965-
| booleanValue # booleanLiteral
958+
| (KW_TRUE | KW_FALSE) # booleanLiteral
966959
| stringLiteral # stringLiteralValues
967960
| BINARY_LITERAL # binaryLiteral
968961
| QUESTION # parameter
@@ -991,7 +984,7 @@ primaryExpression
991984
| name=KW_CURRENT_USER # currentUser
992985
| name=KW_CURRENT_PATH # currentPath
993986
| KW_SUBSTRING LPAREN valueExpression KW_FROM valueExpression (KW_FOR valueExpression)? RPAREN # substring
994-
| KW_NORMALIZE LPAREN valueExpression (COMMA normalForm)? RPAREN # normalize
987+
| KW_NORMALIZE LPAREN valueExpression (COMMA (KW_NFD | KW_NFC | KW_NFKD | KW_NFKC))? RPAREN # normalize
995988
| KW_EXTRACT LPAREN identifier KW_FROM valueExpression RPAREN # extract
996989
| LPAREN expression RPAREN # parenthesizedExpression
997990
| KW_GROUPING LPAREN (qualifiedName (COMMA qualifiedName)*)? RPAREN # groupingOperation
@@ -1017,11 +1010,6 @@ comparisonQuantifier
10171010
| KW_ANY
10181011
;
10191012

1020-
booleanValue
1021-
: KW_TRUE
1022-
| KW_FALSE
1023-
;
1024-
10251013
interval
10261014
: INTEGER_VALUE intervalField
10271015
| LPAREN INTEGER_VALUE RPAREN intervalField
@@ -1044,13 +1032,6 @@ intervalField
10441032
| KW_SECONDS
10451033
;
10461034

1047-
normalForm
1048-
: KW_NFD
1049-
| KW_NFC
1050-
| KW_NFKD
1051-
| KW_NFKC
1052-
;
1053-
10541035
type
10551036
: type KW_ARRAY
10561037
| KW_ARRAY LT type GT
@@ -1116,10 +1097,8 @@ over
11161097
* https://github.com/tunnelvisionlabs/antlr4ts/issues/417
11171098
*/
11181099
windowFrame
1119-
: frameType=KW_RANGE start_=frameBound
1120-
| frameType=KW_ROWS start_=frameBound
1121-
| frameType=KW_RANGE KW_BETWEEN start_=frameBound KW_AND end=frameBound
1122-
| frameType=KW_ROWS KW_BETWEEN start_=frameBound KW_AND end=frameBound
1100+
: frameType=(KW_RANGE | KW_ROWS) start_=frameBound
1101+
| frameType=(KW_RANGE | KW_ROWS) KW_BETWEEN start_=frameBound KW_AND end=frameBound
11231102
;
11241103

11251104
frameBound

src/lib/impala/ImpalaSqlParser.interp

Lines changed: 1 addition & 5 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)