Skip to content

Commit 3101b0e

Browse files
committed
feat: match empty column when in entityCollecting context
1 parent c8c64c0 commit 3101b0e

35 files changed

+38944
-37922
lines changed

src/grammar/flink/FlinkSqlParser.g4

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,24 @@ columnNameCreate
184184
| expression
185185
;
186186

187+
emptyColumn
188+
:
189+
;
190+
187191
columnName
188-
: uid
189-
| {this.shouldMatchEmpty()}?
192+
: uidAllowEmpty
193+
| {this.shouldMatchEmpty()}? emptyColumn
190194
;
191195

192196
columnNamePath
193197
: uid
194198
;
195199

200+
columnNamePathAllowEmpty
201+
: uidAllowEmpty
202+
| {this.shouldMatchEmpty()}? emptyColumn
203+
;
204+
196205
columnNameList
197206
: LR_BRACKET columnName (COMMA columnName)* RR_BRACKET
198207
;
@@ -614,12 +623,12 @@ columnDescriptor
614623
;
615624

616625
joinCondition
617-
: KW_ON booleanExpression
626+
: KW_ON (booleanExpression | columnNamePathAllowEmpty (EQUAL_SYMBOL columnNamePathAllowEmpty)?)
618627
| KW_USING columnNameList
619628
;
620629

621630
whereClause
622-
: KW_WHERE booleanExpression
631+
: KW_WHERE (booleanExpression | columnNamePathAllowEmpty)
623632
;
624633

625634
groupByClause
@@ -983,6 +992,11 @@ uid
983992
: identifier (DOT identifier)*
984993
;
985994

995+
uidAllowEmpty
996+
: identifier (DOT identifier)*
997+
| {this.shouldMatchEmpty()}? identifier DOT emptyColumn
998+
;
999+
9861000
withOption
9871001
: KW_WITH tablePropertyList
9881002
;

src/grammar/hive/HiveSqlParser.g4

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,19 @@ columnNameList
754754
;
755755

756756
columnName
757-
: poolPath
758-
| {this.shouldMatchEmpty()}?
757+
: poolPathAllowEmpty
758+
| {this.shouldMatchEmpty()}? emptyColumn
759759
;
760760

761761
columnNamePath
762762
: poolPath
763763
;
764764

765+
columnNamePathAllowEmpty
766+
: poolPathAllowEmpty
767+
| {this.shouldMatchEmpty()}? emptyColumn
768+
;
769+
765770
columnNameCreate
766771
: id_
767772
;
@@ -1346,7 +1351,10 @@ atomjoinSource
13461351

13471352
joinSource
13481353
: atomjoinSource (
1349-
joinToken joinSourcePart (KW_ON expression | KW_USING columnParenthesesList)?
1354+
joinToken joinSourcePart (
1355+
KW_ON (expression | columnNamePathAllowEmpty (EQUAL columnNamePathAllowEmpty)?)
1356+
| KW_USING columnParenthesesList
1357+
)?
13501358
)*
13511359
;
13521360

@@ -1469,7 +1477,7 @@ Rules for parsing whereClause
14691477
where a=b and ...
14701478
*/
14711479
whereClause
1472-
: KW_WHERE expression
1480+
: KW_WHERE (expression | columnNamePathAllowEmpty)
14731481
;
14741482

14751483
/**
@@ -1600,7 +1608,7 @@ groupingSetExpression
16001608
;
16011609

16021610
havingClause
1603-
: KW_HAVING expression
1611+
: KW_HAVING (expression | columnNamePathAllowEmpty)
16041612
;
16051613

16061614
qualifyClause
@@ -2425,10 +2433,19 @@ decimal
24252433
| KW_NUMERIC
24262434
;
24272435

2436+
emptyColumn
2437+
:
2438+
;
2439+
24282440
poolPath
24292441
: id_ (DOT id_)*
24302442
;
24312443

2444+
poolPathAllowEmpty
2445+
: id_ (DOT id_)*
2446+
| {this.shouldMatchEmpty()}? id_ (DOT emptyColumn)*
2447+
;
2448+
24322449
triggerAtomExpression
24332450
: id_ GREATERTHAN (Number | StringLiteral)
24342451
;

src/grammar/impala/ImpalaSqlParser.g4

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,24 @@ functionNamePath
558558
| qualifiedName
559559
;
560560

561+
emptyColumn
562+
:
563+
;
564+
561565
columnNamePath
562-
: qualifiedName
563-
| {this.shouldMatchEmpty()}?
566+
: {this.shouldMatchEmpty()}? emptyColumn
567+
| qualifiedNameAllowEmpty
564568
;
565569

566570
columnName
567571
: qualifiedName
568572
;
569573

574+
columnNameAllowEmpty
575+
: {this.shouldMatchEmpty()}? emptyColumn
576+
| qualifiedNameAllowEmpty
577+
;
578+
570579
tableOrViewPath
571580
: tableNamePath
572581
| viewNamePath
@@ -781,11 +790,11 @@ selectList
781790
;
782791

783792
whereClause
784-
: KW_WHERE where=booleanExpression
793+
: KW_WHERE (where=booleanExpression | columnNameAllowEmpty)
785794
;
786795

787796
havingClause
788-
: KW_HAVING having=booleanExpression
797+
: KW_HAVING (having=booleanExpression | columnNameAllowEmpty)
789798
;
790799

791800
groupBy
@@ -854,7 +863,7 @@ joinType
854863
;
855864

856865
joinCriteria
857-
: KW_ON booleanExpression
866+
: KW_ON (booleanExpression | columnNameAllowEmpty)
858867
| KW_USING LPAREN identifier (COMMA identifier)* RPAREN
859868
;
860869

@@ -1149,6 +1158,11 @@ qualifiedName
11491158
: identifier (DOT identifier)*
11501159
;
11511160

1161+
qualifiedNameAllowEmpty
1162+
: {this.shouldMatchEmpty()}? (identifier DOT emptyColumn | emptyColumn)
1163+
| identifier (DOT identifier)*
1164+
;
1165+
11521166
principal
11531167
: KW_ROLE identifier # rolePrincipal
11541168
| KW_USER identifier # userPrincipal

src/grammar/mysql/MySqlParser.g4

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ joinPart
11221122
;
11231123

11241124
joinSpec
1125-
: (KW_ON expression)
1125+
: (KW_ON (expression | columnNamePathAllowEmpty))
11261126
| KW_USING '(' columnNames ')'
11271127
;
11281128

@@ -1249,7 +1249,7 @@ selectLinesInto
12491249
;
12501250

12511251
fromClause
1252-
: (KW_FROM tableSources)? (KW_WHERE whereExpr=expression)?
1252+
: (KW_FROM tableSources)? (KW_WHERE (whereExpr=expression | columnNamePathAllowEmpty))?
12531253
;
12541254

12551255
groupByClause
@@ -2419,10 +2419,24 @@ columnNames
24192419
: columnName (',' columnName)*
24202420
;
24212421

2422+
emptyColumn
2423+
:
2424+
;
2425+
24222426
columnName
2427+
: uid (dottedIdAllowEmpty dottedIdAllowEmpty?)?
2428+
| .? dottedId dottedId?
2429+
| {this.shouldMatchEmpty()}? emptyColumn
2430+
;
2431+
2432+
columnNamePath
24232433
: uid (dottedId dottedId?)?
24242434
| .? dottedId dottedId?
2425-
| {this.shouldMatchEmpty()}?
2435+
;
2436+
2437+
columnNamePathAllowEmpty
2438+
: {this.shouldMatchEmpty()}? emptyColumn
2439+
| uid (dottedIdAllowEmpty dottedIdAllowEmpty?)?
24262440
;
24272441

24282442
tableSpaceNameCreate
@@ -2560,6 +2574,12 @@ dottedId
25602574
| '.' uid
25612575
;
25622576

2577+
dottedIdAllowEmpty
2578+
: DOT ID
2579+
| '.' uid
2580+
| {this.shouldMatchEmpty()}? DOT emptyColumn
2581+
;
2582+
25632583
decimalLiteral
25642584
: DECIMAL_LITERAL
25652585
| ZERO_DECIMAL
@@ -2998,7 +3018,7 @@ expressionAtom
29983018
| left=expressionAtom jsonOperator right=expressionAtom # jsonExpressionAtom
29993019
| left=expressionAtom bitOperator right=expressionAtom # bitExpressionAtom
30003020
| left=expressionAtom mathOperator right=expressionAtom # mathExpressionAtom
3001-
| columnName # columnNameExpressionAtom
3021+
| columnNamePath # columnNameExpressionAtom
30023022
;
30033023

30043024
unaryOperator

src/grammar/postgresql/PostgreSqlParser.g4

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2722,13 +2722,18 @@ procedureNameCreate
27222722
| colId indirection
27232723
;
27242724

2725+
emptyColumn
2726+
:
2727+
;
2728+
27252729
columnName
27262730
: colId optIndirection
2727-
| {this.shouldMatchEmpty()}?
2731+
| {this.shouldMatchEmpty()}? (colId DOT emptyColumn | emptyColumn)
27282732
;
27292733

27302734
columnNamePath
27312735
: colId optIndirection
2736+
| {this.shouldMatchEmpty()}? (colId DOT emptyColumn | emptyColumn)
27322737
;
27332738

27342739
columnNameCreate

src/grammar/spark/SparkSqlParser.g4

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,24 @@ viewName
413413
: viewIdentifier
414414
;
415415

416+
emptyColumn
417+
:
418+
;
419+
416420
columnName
417-
: multipartIdentifier
418-
| {this.shouldMatchEmpty()}?
421+
: multipartIdentifierAllowEmpty
422+
| {this.shouldMatchEmpty()}? emptyColumn
419423
;
420424

421425
columnNamePath
422426
: multipartIdentifier
423427
;
424428

429+
columnNamePathAllowEmpty
430+
: multipartIdentifierAllowEmpty
431+
| {this.shouldMatchEmpty()}? emptyColumn
432+
;
433+
425434
columnNameSeq
426435
: columnName (COMMA columnName)*
427436
;
@@ -680,7 +689,7 @@ joinType
680689
;
681690

682691
joinCriteria
683-
: KW_ON booleanExpression
692+
: KW_ON (booleanExpression | columnNamePathAllowEmpty (EQ columnNamePathAllowEmpty)?)
684693
| KW_USING identifierList
685694
;
686695

@@ -804,6 +813,11 @@ multipartIdentifier
804813
: parts+=errorCapturingIdentifier (DOT parts+=errorCapturingIdentifier)*
805814
;
806815

816+
multipartIdentifierAllowEmpty
817+
: multipartIdentifier
818+
| {this.shouldMatchEmpty()}? multipartIdentifier DOT emptyColumn
819+
;
820+
807821
multipartIdentifierPropertyList
808822
: multipartIdentifierProperty (COMMA multipartIdentifierProperty)*
809823
;

src/lib/flink/FlinkSqlParser.interp

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

0 commit comments

Comments
 (0)