Skip to content

Commit 31b57a4

Browse files
authored
fix: #295 #297 optimize impala data types suggestion and create table (#296)
* fix: #295 impala data types suggestion * fix: #297 impala create table with STRUCT
1 parent fa30fe9 commit 31b57a4

13 files changed

Lines changed: 5578 additions & 5088 deletions

src/grammar/impala/ImpalaSqlLexer.g4

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ KW_LOAD : 'LOAD';
151151
KW_LOCALTIME : 'LOCALTIME';
152152
KW_LOCALTIMESTAMP : 'LOCALTIMESTAMP';
153153
KW_METADATA : 'METADATA';
154-
KW_MAP : 'MAP';
155154
KW_MINUTE : 'MINUTE';
156155
KW_MINUTES : 'MINUTES';
157156
KW_MONTH : 'MONTH';
@@ -213,7 +212,6 @@ KW_SHOW : 'SHOW';
213212
KW_SHUTDOWN : 'SHUTDOWN';
214213
KW_SOME : 'SOME';
215214
KW_STATS : 'STATS';
216-
KW_STRUCT : 'STRUCT';
217215
KW_STRAIGHT_JOIN : 'STRAIGHT_JOIN';
218216
KW_SUBSTRING : 'SUBSTRING';
219217
KW_SYSTEM : 'SYSTEM';
@@ -259,6 +257,26 @@ KW_REFERENCES : 'REFERENCES';
259257
KW_NOVALIDATE : 'NOVALIDATE';
260258
KW_RELY : 'RELY';
261259

260+
// dataType
261+
KW_BINARY : 'BINARY';
262+
KW_BIGINT : 'BIGINT';
263+
KW_BOOLEAN : 'BOOLEAN';
264+
KW_CHAR : 'CHAR';
265+
KW_DATE : 'DATE';
266+
KW_DECIMAL : 'DECIMAL';
267+
KW_DOUBLE : 'DOUBLE';
268+
KW_INT : 'INT';
269+
KW_MAP : 'MAP';
270+
KW_REAL : 'REAL';
271+
KW_SMALLINT : 'SMALLINT';
272+
KW_FLOAT : 'FLOAT';
273+
KW_STRING : 'STRING';
274+
KW_STRUCT : 'STRUCT';
275+
KW_TIMESTAMP : 'TIMESTAMP';
276+
KW_TINYINT : 'TINYINT';
277+
KW_VARCHAR : 'VARCHAR';
278+
KW_COMPLEX : 'COMPLEX';
279+
262280
STATS_NUMDVS : '\'NUMDVS\'';
263281
STATS_NUMNULLS : '\'NUMNULLS\'';
264282
STATS_AVGSIZE : '\'AVGSIZE\'';

src/grammar/impala/ImpalaSqlParser.g4

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ computeStats
265265
;
266266

267267
computeIncrementalStats
268-
: KW_COMPUTE KW_INCREMENTAL KW_STATS tableNamePath (KW_PARTITION expression)?
268+
: KW_COMPUTE KW_INCREMENTAL KW_STATS tableNamePath (KW_PARTITION LPAREN expression RPAREN)?
269269
;
270270

271271
dropStatement
@@ -1003,8 +1003,30 @@ type
10031003
: type KW_ARRAY
10041004
| KW_ARRAY LT type GT
10051005
| KW_MAP LT type COMMA type GT
1006-
| KW_STRUCT LT identifier COLON type (COMMA identifier COLON type)* GT
1007-
| baseType (LPAREN typeParameter (COMMA typeParameter)* RPAREN)?
1006+
| KW_STRUCT LT identifier type (COMMA identifier type)* GT
1007+
| (baseType | dataType) (LPAREN typeParameter (COMMA typeParameter)* RPAREN)?
1008+
;
1009+
1010+
dataType
1011+
: KW_ARRAY
1012+
| KW_BINARY
1013+
| KW_BIGINT
1014+
| KW_BOOLEAN
1015+
| KW_CHAR
1016+
| KW_DATE
1017+
| KW_DECIMAL
1018+
| KW_DOUBLE
1019+
| KW_FLOAT
1020+
| KW_INT
1021+
| KW_MAP
1022+
| KW_REAL
1023+
| KW_SMALLINT
1024+
| KW_STRING
1025+
| KW_STRUCT
1026+
| KW_TIMESTAMP
1027+
| KW_TINYINT
1028+
| KW_VARCHAR
1029+
| KW_COMPLEX
10081030
;
10091031

10101032
typeParameter
@@ -1125,6 +1147,7 @@ nonReserved
11251147
// IMPORTANT: this rule must only contain tokens. Nested rules are not supported. See SqlParser.exitNonReserved
11261148
: KW_BERNOULLI
11271149
| KW_DAY
1150+
| KW_DATE
11281151
| KW_DAYS
11291152
| KW_EXCLUDING
11301153
| KW_HOUR

src/lib/impala/ImpalaSqlLexer.interp

Lines changed: 55 additions & 7 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)