Skip to content

Commit 9dd12c4

Browse files
committed
feat(impala): add syntax suggestion
1 parent 3dfdb1d commit 9dd12c4

File tree

8 files changed

+3476
-3380
lines changed

8 files changed

+3476
-3380
lines changed

src/grammar/impala/ImpalaSqlParser.g4

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ statement
5454

5555
statementDefault: query;
5656

57-
use: KW_USE schema=identifier;
57+
use: KW_USE databaseNamePath;
5858

5959
createStatement
6060
: createSchema
@@ -77,7 +77,7 @@ createTableSelect
7777

7878
createTableLike
7979
: KW_CREATE KW_EXTERNAL? KW_TABLE ifNotExists? tableNameCreate
80-
KW_LIKE (likeTableName=qualifiedName | KW_PARQUET parquet=stringLiteral)
80+
KW_LIKE (tableNamePath | KW_PARQUET parquet=stringLiteral)
8181
(KW_PARTITIONED KW_BY partitionedBy)?
8282
createCommonItem
8383
;
@@ -172,7 +172,7 @@ dropPartitionByRangeOrValue: KW_ALTER KW_TABLE tableNamePath KW_DROP ifExists? (
172172

173173
alterView: KW_ALTER KW_VIEW viewNamePath viewColumns? KW_AS query;
174174

175-
renameView: KW_ALTER KW_VIEW viewNamePath KW_RENAME KW_TO qualifiedName;
175+
renameView: KW_ALTER KW_VIEW viewNamePath KW_RENAME KW_TO viewNamePath;
176176

177177
alterViewOwner: KW_ALTER KW_VIEW viewNamePath KW_SET KW_OWNER (KW_USER|KW_ROLE) qualifiedName;
178178

@@ -244,11 +244,11 @@ deleteStatement
244244
| deleteTableRef
245245
;
246246

247-
delete: KW_DELETE KW_FROM? qualifiedName (KW_WHERE booleanExpression)?;
247+
delete: KW_DELETE KW_FROM? tableNamePath (KW_WHERE booleanExpression)?;
248248

249-
deleteTableRef: KW_DELETE qualifiedName (KW_AS? identifier)? KW_FROM (relation (COMMA relation)*)? (KW_WHERE booleanExpression)?;
249+
deleteTableRef: KW_DELETE tableNamePath (KW_AS? identifier)? KW_FROM (relation (COMMA relation)*)? (KW_WHERE booleanExpression)?;
250250

251-
updateStatement: KW_UPDATE qualifiedName KW_SET assignmentList (KW_FROM relation (COMMA relation)*)? (KW_WHERE booleanExpression)?;
251+
updateStatement: KW_UPDATE tableNamePath KW_SET assignmentList (KW_FROM relation (COMMA relation)*)? (KW_WHERE booleanExpression)?;
252252

253253
upsertStatement: KW_UPSERT KW_INTO KW_TABLE? tableNamePath columnAliases? query;
254254

@@ -376,7 +376,7 @@ viewNameCreate
376376
| identifier (DOT identifier)?
377377
;
378378

379-
functionNameCreate: qualifiedName;
379+
functionNameCreate: identifier;
380380

381381
databaseNamePath: identifier;
382382

@@ -390,7 +390,7 @@ viewNamePath
390390
| identifier (DOT identifier)?
391391
;
392392

393-
functionNamePath: qualifiedName;
393+
functionNamePath: identifier;
394394

395395
columnNamePath
396396
: identifier
@@ -437,7 +437,7 @@ constraintSpecification
437437

438438
foreignKeySpecification
439439
:
440-
KW_FOREIGN KW_KEY columnAliases KW_REFERENCES tblName=qualifiedName columnAliases (KW_DISABLE)? (KW_NOVALIDATE)? (KW_RELY)?
440+
KW_FOREIGN KW_KEY columnAliases KW_REFERENCES tableNamePath columnAliases (KW_DISABLE)? (KW_NOVALIDATE)? (KW_RELY)?
441441
;
442442

443443
columnDefinition
@@ -592,7 +592,7 @@ groupingSet
592592
;
593593

594594
namedQuery
595-
: name=identifier (columnAliases)? KW_AS LPAREN query RPAREN
595+
: name=identifier (columnAliases)? KW_AS subQueryRelation
596596
;
597597

598598
setQuantifier
@@ -652,13 +652,16 @@ columnAliases
652652
;
653653

654654
relationPrimary
655-
: qualifiedName #tableName
656-
| LPAREN query RPAREN #subqueryRelation
657-
| KW_UNNEST LPAREN expression (COMMA expression)* RPAREN (KW_WITH KW_ORDINALITY)? #unnest
658-
| KW_LATERAL LPAREN query RPAREN #lateral
659-
| LPAREN relation RPAREN #parenthesizedRelation
655+
: tableNamePath
656+
| KW_LATERAL? subQueryRelation
657+
| unnest
658+
| parenthesizedRelation
660659
;
661660

661+
subQueryRelation: LPAREN query RPAREN;
662+
unnest: KW_UNNEST LPAREN expression (COMMA expression)* RPAREN (KW_WITH KW_ORDINALITY)?;
663+
parenthesizedRelation: LPAREN relation RPAREN;
664+
662665
expression
663666
: booleanExpression
664667
;
@@ -672,10 +675,10 @@ booleanExpression
672675

673676
predicate[ParserRuleContext value]
674677
: comparisonOperator right=valueExpression #comparison
675-
| comparisonOperator comparisonQuantifier LPAREN query RPAREN #quantifiedComparison
678+
| comparisonOperator comparisonQuantifier subQueryRelation #quantifiedComparison
676679
| KW_NOT? KW_BETWEEN lower=valueExpression KW_AND upper=valueExpression #between
677680
| KW_NOT? KW_IN LPAREN expression (COMMA expression)* RPAREN #inList
678-
| KW_NOT? KW_IN LPAREN query RPAREN #inSubquery
681+
| KW_NOT? KW_IN subQueryRelation #inSubquery
679682
| KW_NOT? KW_LIKE pattern=valueExpression (KW_ESCAPE escape=valueExpression)? #like
680683
| KW_REGEXP pattern=valueExpression #REGEXP
681684
| KW_IS KW_NOT? KW_NULL #nullPredicate
@@ -703,8 +706,8 @@ primaryExpression
703706
| KW_POSITION LPAREN valueExpression KW_IN valueExpression RPAREN #position
704707
| LPAREN expression (KW_AS type)? (COMMA expression (KW_AS type)?)*? RPAREN #rowConstructor
705708
| KW_ROW LPAREN expression (COMMA expression)* RPAREN #rowConstructor
706-
| qualifiedName LPAREN ASTERISK RPAREN filter? over? #functionCall
707-
| qualifiedName LPAREN (setQuantifier? expression (COMMA expression)*)?
709+
| functionNamePath LPAREN ASTERISK RPAREN filter? over? #functionCall
710+
| functionNamePath LPAREN (setQuantifier? expression (COMMA expression)*)?
708711
(KW_ORDER KW_BY sortItem (COMMA sortItem)*)? RPAREN filter? over? #functionCall
709712
| identifier RIGHT_ARROW expression #lambda
710713
| LPAREN (identifier (COMMA identifier)*)? RPAREN RIGHT_ARROW expression #lambda

src/lib/impala/ImpalaSqlParser.interp

Lines changed: 4 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)