Skip to content

Commit cd3fadd

Browse files
author
zhaoge
committed
fix: #478 column completion and incomplete SELECT validate
1 parent 1e853da commit cd3fadd

25 files changed

Lines changed: 12820 additions & 11952 deletions

src/grammar/mysql/MySqlParser.g4

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ orderByClause
10711071
;
10721072

10731073
orderByExpression
1074-
: expression order=(KW_ASC | KW_DESC)?
1074+
: (expression | columnNamePathAllowEmpty) order=(KW_ASC | KW_DESC)?
10751075
;
10761076

10771077
tableSources
@@ -1258,15 +1258,15 @@ groupByClause
12581258
;
12591259

12601260
havingClause
1261-
: KW_HAVING havingExpr=expression
1261+
: KW_HAVING (havingExpr=expression | columnNamePathAllowEmpty)
12621262
;
12631263

12641264
windowClause
12651265
: KW_WINDOW windowName KW_AS '(' windowSpec ')' (',' windowName KW_AS '(' windowSpec ')')*
12661266
;
12671267

12681268
groupByItem
1269-
: expression order=(KW_ASC | KW_DESC)?
1269+
: (expression | columnNamePathAllowEmpty) order=(KW_ASC | KW_DESC)?
12701270
;
12711271

12721272
limitClause
@@ -2431,13 +2431,14 @@ columnName
24312431
;
24322432

24332433
columnNamePath
2434-
: uid (dottedId dottedId?)?
2435-
| .? dottedId dottedId?
2434+
: uid (dottedId dottedId?)? # columnNamePath_default
2435+
| .? dottedId dottedId? # columnNamePath_dotted
2436+
| uid DOT {this.shouldMatchEmpty()}? emptyColumn # columnNamePath_dot_empty
24362437
;
24372438

24382439
columnNamePathAllowEmpty
2439-
: {this.shouldMatchEmpty()}? emptyColumn
2440-
| uid (dottedId dottedId?)?
2440+
: columnNamePath
2441+
| {this.shouldMatchEmpty()}? emptyColumn
24412442
;
24422443

24432444
tableSpaceNameCreate

src/grammar/postgresql/PostgreSqlParser.g4

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ options {
4040
superClass=SQLParserBase;
4141
}
4242

43+
@parser::members {
44+
isFollowedByInto(): boolean {
45+
return this.tokenStream.LA(1) === PostgreSqlParser.KW_INTO;
46+
}
47+
48+
isFollowedByEnd(): boolean {
49+
const la = this.tokenStream.LA(1);
50+
return la === PostgreSqlParser.SEMI || la === PostgreSqlParser.EOF;
51+
}
52+
}
53+
4354
@header {
4455
import { SQLParserBase } from '../SQLParserBase';
4556
}
@@ -2629,7 +2640,8 @@ optIndirection
26292640
;
26302641

26312642
targetList
2632-
: targetEl (COMMA targetEl)*
2643+
: {this.isFollowedByInto() || this.isFollowedByEnd()}?
2644+
| targetEl (COMMA targetEl)*
26332645
;
26342646

26352647
targetEl
@@ -2735,7 +2747,8 @@ columnName
27352747
;
27362748

27372749
columnNamePath
2738-
: colId optIndirection
2750+
: colId optIndirection # columnNamePath_default
2751+
| colId DOT {this.shouldMatchEmpty()}? emptyColumn # columnNamePath_dot_empty
27392752
;
27402753

27412754
columnNameCreate
@@ -3628,5 +3641,5 @@ anyIdentifier
36283641
;
36293642

36303643
sqlExpression
3631-
: targetList? intoClause? fromClause? whereClause? groupClause? havingClause? windowClause?
3644+
: targetList intoClause? fromClause? whereClause? groupClause? havingClause? windowClause?
36323645
;

src/grammar/trino/TrinoSql.g4

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ options {
2929
superClass=SQLParserBase;
3030
}
3131

32+
@parser::members {
33+
notEntityCollecting(): boolean {
34+
return !this.entityCollecting;
35+
}
36+
}
37+
3238
@header {
3339
import { SQLParserBase } from '../SQLParserBase';
3440
}
@@ -380,10 +386,19 @@ joinType
380386
;
381387

382388
joinCriteria
383-
: KW_ON booleanExpression
389+
: KW_ON (joinColumnEquality | {this.notEntityCollecting()}? booleanExpression)
384390
| KW_USING '(' identifier (',' identifier)* ')'
385391
;
386392

393+
joinColumnEquality
394+
: left=joinColumnReference EQ right=joinColumnReference
395+
;
396+
397+
joinColumnReference
398+
: identifier DOT {this.entityCollecting}? emptyColumn
399+
| columnName
400+
;
401+
387402
sampledRelation
388403
: patternRecognition (KW_TABLESAMPLE sampleType '(' percentage=expression ')')?
389404
;
@@ -1039,6 +1054,10 @@ columnRef
10391054
| {this.shouldMatchEmpty()}?
10401055
;
10411056

1057+
emptyColumn
1058+
:
1059+
;
1060+
10421061
columnName
10431062
: qualifiedName
10441063
;

src/lib/mysql/MySqlParser.interp

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

0 commit comments

Comments
 (0)