Skip to content

Commit 1fba7a4

Browse files
committed
test: enhance hive and spark entity collect test case
1 parent 35dd70b commit 1fba7a4

File tree

11 files changed

+507
-136
lines changed

11 files changed

+507
-136
lines changed

src/grammar/spark/SparkSqlParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ tableAllColumns
913913

914914
namedExpression
915915
: (tableAllColumns | selectLiteralColumnName | selectExpressionColumnName) (
916-
KW_AS? (name=errorCapturingIdentifier | identifierList)
916+
KW_AS? (alias=errorCapturingIdentifier | identifierList)
917917
)?
918918
;
919919

src/lib/spark/SparkSqlParser.interp

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

src/lib/spark/SparkSqlParser.ts

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11934,7 +11934,7 @@ export class SparkSqlParser extends SQLParserBase {
1193411934
let localContext = new RelationPrimaryContext(this.context, this.state);
1193511935
this.enterRule(localContext, 224, SparkSqlParser.RULE_relationPrimary);
1193611936
try {
11937-
this.state = 2821;
11937+
this.state = 2819;
1193811938
this.errorHandler.sync(this);
1193911939
switch (this.interpreter.adaptivePredict(this.tokenStream, 359, this.context) ) {
1194011940
case 1:
@@ -11992,64 +11992,60 @@ export class SparkSqlParser extends SQLParserBase {
1199211992
this.enterOuterAlt(localContext, 2);
1199311993
{
1199411994
this.state = 2801;
11995-
this.match(SparkSqlParser.LEFT_PAREN);
11996-
this.state = 2802;
1199711995
this.atomSubQueryTableSource();
1199811996
this.state = 2803;
11999-
this.match(SparkSqlParser.RIGHT_PAREN);
12000-
this.state = 2805;
1200111997
this.errorHandler.sync(this);
1200211998
switch (this.interpreter.adaptivePredict(this.tokenStream, 357, this.context) ) {
1200311999
case 1:
1200412000
{
12005-
this.state = 2804;
12001+
this.state = 2802;
1200612002
this.sample();
1200712003
}
1200812004
break;
1200912005
}
12010-
this.state = 2807;
12006+
this.state = 2805;
1201112007
this.tableAlias();
1201212008
}
1201312009
break;
1201412010
case 3:
1201512011
localContext = new JoinTableSourceContext(localContext);
1201612012
this.enterOuterAlt(localContext, 3);
1201712013
{
12018-
this.state = 2809;
12014+
this.state = 2807;
1201912015
this.match(SparkSqlParser.LEFT_PAREN);
12020-
this.state = 2810;
12016+
this.state = 2808;
1202112017
this.relation();
12022-
this.state = 2811;
12018+
this.state = 2809;
1202312019
this.match(SparkSqlParser.RIGHT_PAREN);
12024-
this.state = 2813;
12020+
this.state = 2811;
1202512021
this.errorHandler.sync(this);
1202612022
switch (this.interpreter.adaptivePredict(this.tokenStream, 358, this.context) ) {
1202712023
case 1:
1202812024
{
12029-
this.state = 2812;
12025+
this.state = 2810;
1203012026
this.sample();
1203112027
}
1203212028
break;
1203312029
}
12034-
this.state = 2815;
12030+
this.state = 2813;
1203512031
this.tableAlias();
1203612032
}
1203712033
break;
1203812034
case 4:
1203912035
localContext = new InlineTableSourceContext(localContext);
1204012036
this.enterOuterAlt(localContext, 4);
1204112037
{
12042-
this.state = 2817;
12038+
this.state = 2815;
1204312039
this.inlineTable();
12044-
this.state = 2818;
12040+
this.state = 2816;
1204512041
this.tableAlias();
1204612042
}
1204712043
break;
1204812044
case 5:
1204912045
localContext = new FunctionTableSourceContext(localContext);
1205012046
this.enterOuterAlt(localContext, 5);
1205112047
{
12052-
this.state = 2820;
12048+
this.state = 2818;
1205312049
this.functionTable();
1205412050
}
1205512051
break;
@@ -12075,8 +12071,12 @@ export class SparkSqlParser extends SQLParserBase {
1207512071
try {
1207612072
this.enterOuterAlt(localContext, 1);
1207712073
{
12078-
this.state = 2823;
12074+
this.state = 2821;
12075+
this.match(SparkSqlParser.LEFT_PAREN);
12076+
this.state = 2822;
1207912077
this.query();
12078+
this.state = 2823;
12079+
this.match(SparkSqlParser.RIGHT_PAREN);
1208012080
}
1208112081
}
1208212082
catch (re) {
@@ -13842,7 +13842,7 @@ export class SparkSqlParser extends SQLParserBase {
1384213842
case SparkSqlParser.BACKQUOTED_IDENTIFIER:
1384313843
{
1384413844
this.state = 3048;
13845-
localContext._name = this.errorCapturingIdentifier();
13845+
localContext._alias = this.errorCapturingIdentifier();
1384613846
}
1384713847
break;
1384813848
case SparkSqlParser.LEFT_PAREN:
@@ -19159,9 +19159,9 @@ export class SparkSqlParser extends SQLParserBase {
1915919159
3,109,2772,8,109,1,110,1,110,1,110,1,110,5,110,2778,8,110,10,110,
1916019160
12,110,2781,9,110,1,110,1,110,1,111,1,111,3,111,2787,8,111,1,112,
1916119161
1,112,1,112,3,112,2792,8,112,1,112,3,112,2795,8,112,1,112,3,112,
19162-
2798,8,112,1,112,1,112,1,112,1,112,1,112,1,112,3,112,2806,8,112,
19163-
1,112,1,112,1,112,1,112,1,112,1,112,3,112,2814,8,112,1,112,1,112,
19164-
1,112,1,112,1,112,1,112,3,112,2822,8,112,1,113,1,113,1,114,1,114,
19162+
2798,8,112,1,112,1,112,1,112,1,112,3,112,2804,8,112,1,112,1,112,
19163+
1,112,1,112,1,112,1,112,3,112,2812,8,112,1,112,1,112,1,112,1,112,
19164+
1,112,1,112,3,112,2820,8,112,1,113,1,113,1,113,1,113,1,114,1,114,
1916519165
1,114,1,114,5,114,2830,8,114,10,114,12,114,2833,9,114,1,115,1,115,
1916619166
1,115,3,115,2838,8,115,1,115,1,115,1,115,1,115,1,115,3,115,2845,
1916719167
8,115,1,115,1,115,1,115,1,115,1,115,3,115,2852,8,115,3,115,2854,
@@ -19360,7 +19360,7 @@ export class SparkSqlParser extends SQLParserBase {
1936019360
1,0,0,0,200,2655,1,0,0,0,202,2674,1,0,0,0,204,2700,1,0,0,0,206,2706,
1936119361
1,0,0,0,208,2708,1,0,0,0,210,2744,1,0,0,0,212,2746,1,0,0,0,214,2750,
1936219362
1,0,0,0,216,2758,1,0,0,0,218,2769,1,0,0,0,220,2773,1,0,0,0,222,2784,
19363-
1,0,0,0,224,2821,1,0,0,0,226,2823,1,0,0,0,228,2825,1,0,0,0,230,2853,
19363+
1,0,0,0,224,2819,1,0,0,0,226,2821,1,0,0,0,228,2825,1,0,0,0,230,2853,
1936419364
1,0,0,0,232,2874,1,0,0,0,234,2894,1,0,0,0,236,2900,1,0,0,0,238,2904,
1936519365
1,0,0,0,240,2906,1,0,0,0,242,2909,1,0,0,0,244,2930,1,0,0,0,246,2981,
1936619366
1,0,0,0,248,2983,1,0,0,0,250,2991,1,0,0,0,252,2999,1,0,0,0,254,3007,
@@ -20210,23 +20210,23 @@ export class SparkSqlParser extends SQLParserBase {
2021020210
2790,1,0,0,0,2792,2794,1,0,0,0,2793,2795,3,150,75,0,2794,2793,1,
2021120211
0,0,0,2794,2795,1,0,0,0,2795,2797,1,0,0,0,2796,2798,3,208,104,0,
2021220212
2797,2796,1,0,0,0,2797,2798,1,0,0,0,2798,2799,1,0,0,0,2799,2800,
20213-
3,244,122,0,2800,2822,1,0,0,0,2801,2802,5,2,0,0,2802,2803,3,226,
20214-
113,0,2803,2805,5,3,0,0,2804,2806,3,208,104,0,2805,2804,1,0,0,0,
20215-
2805,2806,1,0,0,0,2806,2807,1,0,0,0,2807,2808,3,244,122,0,2808,2822,
20216-
1,0,0,0,2809,2810,5,2,0,0,2810,2811,3,198,99,0,2811,2813,5,3,0,0,
20217-
2812,2814,3,208,104,0,2813,2812,1,0,0,0,2813,2814,1,0,0,0,2814,2815,
20218-
1,0,0,0,2815,2816,3,244,122,0,2816,2822,1,0,0,0,2817,2818,3,228,
20219-
114,0,2818,2819,3,244,122,0,2819,2822,1,0,0,0,2820,2822,3,240,120,
20220-
0,2821,2791,1,0,0,0,2821,2801,1,0,0,0,2821,2809,1,0,0,0,2821,2817,
20221-
1,0,0,0,2821,2820,1,0,0,0,2822,225,1,0,0,0,2823,2824,3,26,13,0,2824,
20222-
227,1,0,0,0,2825,2826,5,333,0,0,2826,2831,3,280,140,0,2827,2828,
20223-
5,4,0,0,2828,2830,3,280,140,0,2829,2827,1,0,0,0,2830,2833,1,0,0,
20224-
0,2831,2829,1,0,0,0,2831,2832,1,0,0,0,2832,229,1,0,0,0,2833,2831,
20225-
1,0,0,0,2834,2835,5,293,0,0,2835,2837,3,86,43,0,2836,2838,3,232,
20226-
116,0,2837,2836,1,0,0,0,2837,2838,1,0,0,0,2838,2854,1,0,0,0,2839,
20227-
2840,5,293,0,0,2840,2841,5,2,0,0,2841,2842,3,86,43,0,2842,2844,5,
20228-
3,0,0,2843,2845,3,232,116,0,2844,2843,1,0,0,0,2844,2845,1,0,0,0,
20229-
2845,2854,1,0,0,0,2846,2847,5,293,0,0,2847,2848,5,2,0,0,2848,2849,
20213+
3,244,122,0,2800,2820,1,0,0,0,2801,2803,3,226,113,0,2802,2804,3,
20214+
208,104,0,2803,2802,1,0,0,0,2803,2804,1,0,0,0,2804,2805,1,0,0,0,
20215+
2805,2806,3,244,122,0,2806,2820,1,0,0,0,2807,2808,5,2,0,0,2808,2809,
20216+
3,198,99,0,2809,2811,5,3,0,0,2810,2812,3,208,104,0,2811,2810,1,0,
20217+
0,0,2811,2812,1,0,0,0,2812,2813,1,0,0,0,2813,2814,3,244,122,0,2814,
20218+
2820,1,0,0,0,2815,2816,3,228,114,0,2816,2817,3,244,122,0,2817,2820,
20219+
1,0,0,0,2818,2820,3,240,120,0,2819,2791,1,0,0,0,2819,2801,1,0,0,
20220+
0,2819,2807,1,0,0,0,2819,2815,1,0,0,0,2819,2818,1,0,0,0,2820,225,
20221+
1,0,0,0,2821,2822,5,2,0,0,2822,2823,3,26,13,0,2823,2824,5,3,0,0,
20222+
2824,227,1,0,0,0,2825,2826,5,333,0,0,2826,2831,3,280,140,0,2827,
20223+
2828,5,4,0,0,2828,2830,3,280,140,0,2829,2827,1,0,0,0,2830,2833,1,
20224+
0,0,0,2831,2829,1,0,0,0,2831,2832,1,0,0,0,2832,229,1,0,0,0,2833,
20225+
2831,1,0,0,0,2834,2835,5,293,0,0,2835,2837,3,86,43,0,2836,2838,3,
20226+
232,116,0,2837,2836,1,0,0,0,2837,2838,1,0,0,0,2838,2854,1,0,0,0,
20227+
2839,2840,5,293,0,0,2840,2841,5,2,0,0,2841,2842,3,86,43,0,2842,2844,
20228+
5,3,0,0,2843,2845,3,232,116,0,2844,2843,1,0,0,0,2844,2845,1,0,0,
20229+
0,2845,2854,1,0,0,0,2846,2847,5,293,0,0,2847,2848,5,2,0,0,2848,2849,
2023020230
3,26,13,0,2849,2851,5,3,0,0,2850,2852,3,232,116,0,2851,2850,1,0,
2023120231
0,0,2851,2852,1,0,0,0,2852,2854,1,0,0,0,2853,2834,1,0,0,0,2853,2839,
2023220232
1,0,0,0,2853,2846,1,0,0,0,2854,231,1,0,0,0,2855,2856,5,346,0,0,2856,
@@ -20668,7 +20668,7 @@ export class SparkSqlParser extends SQLParserBase {
2066820668
2581,2589,2594,2608,2617,2620,2625,2632,2635,2641,2647,2650,2655,
2066920669
2660,2664,2670,2674,2677,2682,2685,2690,2694,2697,2700,2706,2711,
2067020670
2718,2721,2739,2741,2744,2755,2764,2771,2779,2786,2791,2794,2797,
20671-
2805,2813,2821,2831,2837,2844,2851,2853,2866,2872,2874,2884,2890,
20671+
2803,2811,2819,2831,2837,2844,2851,2853,2866,2872,2874,2884,2890,
2067220672
2892,2900,2904,2916,2919,2924,2928,2930,2939,2951,2953,2960,2967,
2067320673
2973,2979,2981,2988,2996,3004,3010,3015,3022,3035,3043,3046,3050,
2067420674
3052,3059,3070,3077,3087,3092,3096,3106,3113,3126,3128,3136,3138,
@@ -30424,15 +30424,9 @@ export class SubQueryTableSourceContext extends RelationPrimaryContext {
3042430424
super(ctx.parent, ctx.invokingState);
3042530425
super.copyFrom(ctx);
3042630426
}
30427-
public LEFT_PAREN(): antlr.TerminalNode {
30428-
return this.getToken(SparkSqlParser.LEFT_PAREN, 0)!;
30429-
}
3043030427
public atomSubQueryTableSource(): AtomSubQueryTableSourceContext {
3043130428
return this.getRuleContext(0, AtomSubQueryTableSourceContext)!;
3043230429
}
30433-
public RIGHT_PAREN(): antlr.TerminalNode {
30434-
return this.getToken(SparkSqlParser.RIGHT_PAREN, 0)!;
30435-
}
3043630430
public tableAlias(): TableAliasContext {
3043730431
return this.getRuleContext(0, TableAliasContext)!;
3043830432
}
@@ -30597,9 +30591,15 @@ export class AtomSubQueryTableSourceContext extends antlr.ParserRuleContext {
3059730591
public constructor(parent: antlr.ParserRuleContext | null, invokingState: number) {
3059830592
super(parent, invokingState);
3059930593
}
30594+
public LEFT_PAREN(): antlr.TerminalNode {
30595+
return this.getToken(SparkSqlParser.LEFT_PAREN, 0)!;
30596+
}
3060030597
public query(): QueryContext {
3060130598
return this.getRuleContext(0, QueryContext)!;
3060230599
}
30600+
public RIGHT_PAREN(): antlr.TerminalNode {
30601+
return this.getToken(SparkSqlParser.RIGHT_PAREN, 0)!;
30602+
}
3060330603
public override get ruleIndex(): number {
3060430604
return SparkSqlParser.RULE_atomSubQueryTableSource;
3060530605
}
@@ -31523,7 +31523,7 @@ export class TableAllColumnsContext extends antlr.ParserRuleContext {
3152331523

3152431524

3152531525
export class NamedExpressionContext extends antlr.ParserRuleContext {
31526-
public _name?: ErrorCapturingIdentifierContext;
31526+
public _alias?: ErrorCapturingIdentifierContext;
3152731527
public constructor(parent: antlr.ParserRuleContext | null, invokingState: number) {
3152831528
super(parent, invokingState);
3152931529
}

src/parser/common/entityCollector.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ export abstract class EntityCollector {
409409
exitProgram() {
410410
const entities = Array.from(this._entitiesSet);
411411
this.removeCtxAttr();
412-
this.attachAccessibleToEntities(entities);
412+
if (this._caretTokenIndex !== -1) {
413+
this.attachAccessibleToEntities(entities);
414+
}
413415
this._entityStack.clear();
414416
}
415417

src/parser/postgresql/postgreEntityCollector.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
TableAllColumnsContext,
2828
type TableNameContext,
2929
type TableNameCreateContext,
30-
Target_elContext,
3130
Target_labelContext,
3231
Target_listContext,
3332
type ViewNameContext,

0 commit comments

Comments
 (0)