Skip to content

Commit 04484a4

Browse files
committed
feat(impala): add select and delete sql
1 parent 67f0f79 commit 04484a4

File tree

10 files changed

+4365
-3562
lines changed

10 files changed

+4365
-3562
lines changed

src/grammar/impala/ImpalaSqlParser.g4

Lines changed: 137 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ statement
122122
(KW_PARTITION LPAREN expression(COMMA expression)*RPAREN)?
123123
hintClause? query #insertInto
124124
| KW_DELETE KW_FROM? qualifiedName (KW_WHERE booleanExpression)? #delete
125-
| KW_DELETE expression (KW_AS? identifier)? KW_FROM? relation ((COMMA relation)*)? (KW_WHERE booleanExpression)? #deleteTableRef
125+
| KW_DELETE expression (KW_AS? identifier)? KW_FROM relation (COMMA relation)*? (KW_WHERE booleanExpression)? #deleteTableRef
126126
| KW_UPDATE qualifiedName KW_SET assignmentList (KW_FROM relation (COMMA relation)*)? (KW_WHERE booleanExpression)? #updateTable
127127
| KW_UPSERT hintClause? KW_INTO KW_TABLE? qualifiedName
128128
columnAliases?
@@ -248,14 +248,7 @@ rangeClause
248248
: KW_RANGE columnAliases? LPAREN (KW_PARTITION kuduPartitionSpec (COMMA KW_PARTITION kuduPartitionSpec)*?) RPAREN
249249
;
250250
kuduPartitionSpec
251-
: KW_VALUE partitionCol constants | constants rangeOperator KW_VALUES rangeOperator constants
252-
;
253-
constants
254-
: INTEGER_VALUE
255-
| DECIMAL_VALUE
256-
| DOUBLE_VALUE
257-
| string
258-
| booleanValue
251+
: KW_VALUE partitionCol expression | expression rangeOperator KW_VALUES rangeOperator expression
259252
;
260253

261254
cacheSpec
@@ -313,7 +306,7 @@ property
313306
queryNoWith:
314307
queryTerm
315308
(KW_ORDER KW_BY sortItem (COMMA sortItem)*)?
316-
(KW_LIMIT rows=INTEGER_VALUE (KW_OFFSET offset=INTEGER_VALUE )?)?
309+
(KW_LIMIT rows=expression (KW_OFFSET offset=INTEGER_VALUE )?)?
317310
;
318311

319312
queryTerm
@@ -326,7 +319,7 @@ queryPrimary
326319
: querySpecification #queryPrimaryDefault
327320
| KW_TABLE qualifiedName #table
328321
| KW_VALUES expression (COMMA expression)* #inlineTable
329-
| LPAREN queryNoWith RPAREN #subquery
322+
| LPAREN queryNoWith RPAREN #subquery
330323
;
331324

332325
sortItem
@@ -397,7 +390,7 @@ joinCriteria
397390

398391
sampledRelation
399392
: aliasedRelation (
400-
KW_TABLESAMPLE sampleType LPAREN percentage=expression RPAREN
393+
KW_TABLESAMPLE sampleType LPAREN percentage=expression RPAREN (KW_REPEATABLE LPAREN seed=expression RPAREN)?
401394
)?
402395
;
403396

@@ -433,14 +426,14 @@ booleanExpression
433426
| left=booleanExpression operator=KW_OR right=booleanExpression #logicalBinary
434427
;
435428

436-
// workaround for https://github.com/antlr/antlr4/issues/780
437429
predicate[ParserRuleContext value]
438430
: comparisonOperator right=valueExpression #comparison
439431
| comparisonOperator comparisonQuantifier LPAREN query RPAREN #quantifiedComparison
440432
| KW_NOT? KW_BETWEEN lower=valueExpression KW_AND upper=valueExpression #between
441433
| KW_NOT? KW_IN LPAREN expression (COMMA expression)* RPAREN #inList
442434
| KW_NOT? KW_IN LPAREN query RPAREN #inSubquery
443435
| KW_NOT? KW_LIKE pattern=valueExpression (KW_ESCAPE escape=valueExpression)? #like
436+
| KW_REGEXP pattern=valueExpression #REGEXP
444437
| KW_IS KW_NOT? KW_NULL #nullPredicate
445438
| KW_IS KW_NOT? KW_DISTINCT KW_FROM right=valueExpression #distinctFrom
446439
;
@@ -616,31 +609,135 @@ number
616609
| MINUS? INTEGER_VALUE #integerLiteral
617610
;
618611

612+
619613
nonReserved
620-
// IMPORTANT: this rule must only contain tokens. Nested rules are not supported. See SqlParser.exitNonReserved
621-
: KW_ADD | KW_ADMIN | KW_ALL | KW_ANALYZE | KW_ANY | KW_ARRAY | KW_ASC | KW_AT
622-
| KW_BERNOULLI
623-
| KW_CALL | KW_CASCADE | KW_CATALOGS | KW_COLUMN | KW_COLUMNS | KW_COMMENT | KW_COMMIT | KW_COMMITTED | KW_CURRENT
624-
| KW_DATA | KW_DATABASE | KW_DATABASES | KW_DATE | KW_DAY | KW_DAYS | KW_DEFINER | KW_DESC
625-
| KW_EXCLUDING | KW_EXPLAIN
626-
| KW_FETCH | KW_FILTER | KW_FIRST | KW_FOLLOWING | KW_FORMAT | KW_FUNCTIONS
627-
| KW_GRANT | KW_GRANTED | KW_GRANTS | KW_GRAPHVIZ
628-
| KW_HOUR
629-
| KW_IF | KW_INCLUDING | KW_INPUT | KW_INTERVAL | KW_INVOKER | KW_IO | KW_ISOLATION
630-
| KW_JSON
631-
| KW_LAST | KW_LATERAL | KW_LEVEL | KW_LIMIT | KW_LOGICAL
632-
| KW_MAP | KW_MINUTE | KW_MONTH
633-
| KW_NEXT | KW_NFC | KW_NFD | KW_NFKC | KW_NFKD | KW_NO | KW_NONE | KW_NULLIF | KW_NULLS
634-
| KW_OFFSET | KW_ONLY | KW_OPTION | KW_ORDINALITY | KW_OUTPUT | KW_OVER
635-
| KW_PARTITION | KW_PARTITIONS | KW_PARQUET | KW_PATH | KW_POSITION | KW_PRECEDING | KW_PRIVILEGES | KW_PROPERTIES
636-
| KW_RANGE | KW_READ | KW_RENAME | KW_REPEATABLE | KW_REPLACE | KW_RESET | KW_RESTRICT | KW_REVOKE | KW_ROLE | KW_ROLES | KW_ROLLBACK | KW_ROW | KW_ROWS
637-
| KW_SCHEMA | KW_SCHEMAS | KW_SECOND | KW_SECONDS | KW_SECURITY | KW_SERIALIZABLE | KW_SESSION | KW_SET | KW_SETS
638-
| KW_SHOW | KW_SOME | KW_START | KW_STATS | KW_SUBSTRING | KW_SYSTEM
639-
| KW_TABLES | KW_TABLESAMPLE | KW_TEXT | KW_TIES | KW_TIME | KW_TIMESTAMP | KW_TO | KW_TRANSACTION | KW_TRY_CAST | KW_TYPE
640-
| KW_UNBOUNDED | KW_UNCOMMITTED | KW_USE | KW_USER
641-
| KW_VALIDATE | KW_VERBOSE | KW_VIEW | KW_VIEWS
642-
| KW_WORK | KW_WRITE
643-
| KW_YEAR
644-
| KW_ZONE
645-
| KW_DEFAULT
646-
;
614+
// IMPORTANT: this rule must only contain tokens. Nested rules are not supported. See SqlParser.exitNonReserved
615+
:KW_ADD
616+
| KW_ADMIN
617+
| KW_ALL
618+
| KW_ANALYZE
619+
| KW_ANY
620+
| KW_ARRAY
621+
| KW_ASC
622+
| KW_AT
623+
| KW_BERNOULLI
624+
| KW_CALL
625+
| KW_CASCADE
626+
| KW_CATALOGS
627+
| KW_COLUMN
628+
| KW_COLUMNS
629+
| KW_COMMENT
630+
| KW_COMMIT
631+
| KW_COMMITTED
632+
| KW_CURRENT
633+
| KW_DATA
634+
| KW_DATABASE
635+
| KW_DATABASES
636+
| KW_DATE
637+
| KW_DAY
638+
| KW_DAYS
639+
| KW_DEFINER
640+
| KW_DESC
641+
| KW_EXCLUDING
642+
| KW_EXPLAIN
643+
| KW_FETCH
644+
| KW_FILTER
645+
| KW_FIRST
646+
| KW_FOLLOWING
647+
| KW_FORMAT
648+
| KW_FUNCTIONS
649+
| KW_GRANT
650+
| KW_GRANTED
651+
| KW_GRANTS
652+
| KW_GRAPHVIZ
653+
| KW_HOUR
654+
| KW_IF
655+
| KW_INCLUDING
656+
| KW_INPUT
657+
| KW_INTERVAL
658+
| KW_INVOKER
659+
| KW_IO
660+
| KW_ISOLATION
661+
| KW_JSON
662+
| KW_LAST
663+
| KW_LATERAL
664+
| KW_LEVEL
665+
| KW_LIMIT
666+
| KW_LOGICAL
667+
| KW_MAP
668+
| KW_MINUTE
669+
| KW_MONTH
670+
| KW_NEXT
671+
| KW_NFC
672+
| KW_NFD
673+
| KW_NFKC
674+
| KW_NFKD
675+
| KW_NO
676+
| KW_NONE
677+
| KW_NULLIF
678+
| KW_NULLS
679+
| KW_OFFSET
680+
| KW_ONLY
681+
| KW_OPTION
682+
| KW_ORDINALITY
683+
| KW_OUTPUT
684+
| KW_OVER
685+
| KW_PARTITION
686+
| KW_PARTITIONS
687+
| KW_PARQUET
688+
| KW_PATH
689+
| KW_POSITION
690+
| KW_PRECEDING
691+
| KW_PRIVILEGES
692+
| KW_PROPERTIES
693+
| KW_RANGE
694+
| KW_READ
695+
| KW_RENAME
696+
| KW_REPEATABLE
697+
| KW_REPLACE
698+
| KW_RESET
699+
| KW_RESTRICT
700+
| KW_REVOKE
701+
| KW_ROLE
702+
| KW_ROLES
703+
| KW_ROLLBACK
704+
| KW_ROW
705+
| KW_ROWS
706+
| KW_SCHEMA
707+
| KW_SCHEMAS
708+
| KW_SECOND
709+
| KW_SECONDS
710+
| KW_SECURITY
711+
| KW_SERIALIZABLE
712+
| KW_SESSION
713+
| KW_SET
714+
| KW_SETS
715+
| KW_SHOW
716+
| KW_SOME
717+
| KW_START
718+
| KW_STATS
719+
| KW_SUBSTRING
720+
| KW_SYSTEM
721+
| KW_TABLES
722+
| KW_TABLESAMPLE
723+
| KW_TEXT
724+
| KW_TIES
725+
| KW_TIME
726+
| KW_TIMESTAMP
727+
| KW_TO
728+
| KW_TRANSACTION
729+
| KW_TRY_CAST
730+
| KW_TYPE
731+
| KW_UNBOUNDED
732+
| KW_UNCOMMITTED
733+
| KW_USE
734+
| KW_USER
735+
| KW_VALIDATE
736+
| KW_VERBOSE
737+
| KW_VIEW
738+
| KW_VIEWS
739+
| KW_WORK
740+
| KW_WRITE
741+
| KW_YEAR
742+
| KW_ZONE
743+
| KW_DEFAULT;

src/grammar/impala/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Impala SQL Grammar
22

3-
SQL-like HiveQL, [Hive Grammar](https://github.com/apache/hive/tree/master/hplsql/src/main/antlr4/org/apache/hive/hplsql)
3+
SQL-like ImpalaSQL, [Impala Grammar](https://github.com/openlookeng/hetu-core/blob/master/hetu-sql-migration-tool/src/main/antlr4/io/hetu/core/migration/source/impala/ImpalaSql.g4)

src/lib/impala/ImpalaSqlParser.interp

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

src/lib/impala/ImpalaSqlParserListener.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { BetweenContext } from "./ImpalaSqlParserParser";
1616
import { InListContext } from "./ImpalaSqlParserParser";
1717
import { InSubqueryContext } from "./ImpalaSqlParserParser";
1818
import { LikeContext } from "./ImpalaSqlParserParser";
19+
import { REGEXPContext } from "./ImpalaSqlParserParser";
1920
import { NullPredicateContext } from "./ImpalaSqlParserParser";
2021
import { DistinctFromContext } from "./ImpalaSqlParserParser";
2122
import { DecimalLiteralContext } from "./ImpalaSqlParserParser";
@@ -177,7 +178,6 @@ import { KuduPartitionClauseContext } from "./ImpalaSqlParserParser";
177178
import { HashClauseContext } from "./ImpalaSqlParserParser";
178179
import { RangeClauseContext } from "./ImpalaSqlParserParser";
179180
import { KuduPartitionSpecContext } from "./ImpalaSqlParserParser";
180-
import { ConstantsContext } from "./ImpalaSqlParserParser";
181181
import { CacheSpecContext } from "./ImpalaSqlParserParser";
182182
import { RangeOperatorContext } from "./ImpalaSqlParserParser";
183183
import { PartitionColContext } from "./ImpalaSqlParserParser";
@@ -412,6 +412,19 @@ export interface ImpalaSqlParserListener extends ParseTreeListener {
412412
*/
413413
exitLike?: (ctx: LikeContext) => void;
414414

415+
/**
416+
* Enter a parse tree produced by the `REGEXP`
417+
* labeled alternative in `ImpalaSqlParserParser.predicate`.
418+
* @param ctx the parse tree
419+
*/
420+
enterREGEXP?: (ctx: REGEXPContext) => void;
421+
/**
422+
* Exit a parse tree produced by the `REGEXP`
423+
* labeled alternative in `ImpalaSqlParserParser.predicate`.
424+
* @param ctx the parse tree
425+
*/
426+
exitREGEXP?: (ctx: REGEXPContext) => void;
427+
415428
/**
416429
* Enter a parse tree produced by the `nullPredicate`
417430
* labeled alternative in `ImpalaSqlParserParser.predicate`.
@@ -2459,17 +2472,6 @@ export interface ImpalaSqlParserListener extends ParseTreeListener {
24592472
*/
24602473
exitKuduPartitionSpec?: (ctx: KuduPartitionSpecContext) => void;
24612474

2462-
/**
2463-
* Enter a parse tree produced by `ImpalaSqlParserParser.constants`.
2464-
* @param ctx the parse tree
2465-
*/
2466-
enterConstants?: (ctx: ConstantsContext) => void;
2467-
/**
2468-
* Exit a parse tree produced by `ImpalaSqlParserParser.constants`.
2469-
* @param ctx the parse tree
2470-
*/
2471-
exitConstants?: (ctx: ConstantsContext) => void;
2472-
24732475
/**
24742476
* Enter a parse tree produced by `ImpalaSqlParserParser.cacheSpec`.
24752477
* @param ctx the parse tree

0 commit comments

Comments
 (0)