Skip to content

Commit 51c25f6

Browse files
committed
test: update entity collection tests
1 parent 6c9ac43 commit 51c25f6

File tree

8 files changed

+131
-50
lines changed

8 files changed

+131
-50
lines changed

test/parser/flink/suggestion/suggestionWithEntity.test.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ describe('Flink SQL Syntax Suggestion with collect entity', () => {
3232
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
3333

3434
const entities = flink.getAllEntities(sql, pos);
35-
expect(entities.length).toBe(1);
35+
expect(entities.length).toBe(2);
3636
expect(entities[0].text).toBe('tb1');
3737
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
3838
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
39+
40+
expect(entities[1].text).toBe('');
41+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
42+
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
3943
});
4044

4145
test('select with columns with columns and trailing comma', () => {
@@ -76,7 +80,7 @@ describe('Flink SQL Syntax Suggestion with collect entity', () => {
7680
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
7781

7882
const entities = flink.getAllEntities(sql, pos);
79-
expect(entities.length).toBe(4);
83+
expect(entities.length).toBe(5);
8084

8185
const insertTableEntity = entities.find(
8286
(e) => e.entityContextType === EntityContextType.TABLE && e.text === 'insert_tb'
@@ -89,15 +93,18 @@ describe('Flink SQL Syntax Suggestion with collect entity', () => {
8993
e.entityContextType === EntityContextType.TABLE &&
9094
e.declareType === TableDeclareType.EXPRESSION
9195
);
92-
const queryResultEntity = entities.find(
96+
const queryResultEntity = entities.filter(
9397
(e) => e.entityContextType === EntityContextType.QUERY_RESULT
9498
);
9599

96100
expect(insideTableEntity.belongStmt.isContainCaret).toBeTruthy();
97101
expect(insertTableEntity.belongStmt.isContainCaret).toBeTruthy();
98102
expect(derivedTableEntity.belongStmt.isContainCaret).toBeTruthy();
103+
expect(queryResultEntity[0].belongStmt.isContainCaret).toBeTruthy();
104+
expect(queryResultEntity[1].belongStmt.isContainCaret).toBeTruthy();
99105

100-
expect(queryResultEntity.text).toBe('col1, col2, country, state');
106+
expect(queryResultEntity[0].text).toBe('');
107+
expect(queryResultEntity[1].text).toBe('col1, col2, country, state');
101108
});
102109

103110
test('insert into from nested query with columns and trailing comma', () => {
@@ -150,15 +157,19 @@ describe('Flink SQL Syntax Suggestion with collect entity', () => {
150157
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
151158

152159
const entities = flink.getAllEntities(sql, pos);
153-
expect(entities.length).toBe(2);
160+
expect(entities.length).toBe(3);
154161

155162
expect(entities[0].text).toBe('origin_table');
156163
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
157164
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
158165

159-
expect(entities[1].text).toBe('derived_table');
160-
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE_CREATE);
166+
expect(entities[1].text).toBe('');
167+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
161168
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
169+
170+
expect(entities[2].text).toBe('derived_table');
171+
expect(entities[2].entityContextType).toBe(EntityContextType.TABLE_CREATE);
172+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
162173
});
163174

164175
test('create table as select with columns and trailing comma', () => {

test/parser/hive/suggestion/suggestionWithEntity.test.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path';
33
import { HiveSQL } from 'src/parser/hive';
44
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
55
import { commentOtherLine } from 'test/helper';
6+
import { AttrName, CommonEntityContext } from 'src/parser/common/entityCollector';
67

78
const syntaxSql = fs.readFileSync(
89
path.join(__dirname, 'fixtures', 'suggestionWithEntity.sql'),
@@ -31,10 +32,14 @@ describe('Hive SQL Syntax Suggestion with collect entity', () => {
3132
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
3233

3334
const entities = hive.getAllEntities(sql, pos);
34-
expect(entities.length).toBe(1);
35+
expect(entities.length).toBe(2);
3536
expect(entities[0].text).toBe('tb1');
3637
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
3738
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
39+
40+
expect(entities[1].text).toBe('');
41+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
42+
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
3843
});
3944

4045
test('select with columns with columns and trailing comma', () => {
@@ -73,10 +78,14 @@ describe('Hive SQL Syntax Suggestion with collect entity', () => {
7378
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
7479

7580
const entities = hive.getAllEntities(sql, pos);
76-
expect(entities.length).toBe(1);
81+
expect(entities.length).toBe(2);
7782
expect(entities[0].text).toBe('table_name_1');
7883
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
7984
expect(entities[0].belongStmt.rootStmt.isContainCaret).toBeTruthy();
85+
86+
expect(entities[1].text).toBe('');
87+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
88+
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
8089
});
8190

8291
test('from table select with with columns and trailing comma', () => {
@@ -115,7 +124,7 @@ describe('Hive SQL Syntax Suggestion with collect entity', () => {
115124
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
116125

117126
const entities = hive.getAllEntities(sql, pos);
118-
expect(entities.length).toBe(2);
127+
expect(entities.length).toBe(3);
119128
expect(entities[0].text).toBe('a');
120129
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
121130
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
@@ -125,6 +134,10 @@ describe('Hive SQL Syntax Suggestion with collect entity', () => {
125134
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
126135
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
127136
expect(entities[1].belongStmt.rootStmt.isContainCaret).toBeTruthy();
137+
138+
expect(entities[2].text).toBe('');
139+
expect(entities[2].entityContextType).toBe(EntityContextType.QUERY_RESULT);
140+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
128141
});
129142

130143
test('from joined table select with columns and trailing comma', () => {
@@ -224,15 +237,28 @@ describe('Hive SQL Syntax Suggestion with collect entity', () => {
224237
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
225238

226239
const entities = hive.getAllEntities(sql, pos);
227-
expect(entities.length).toBe(4);
240+
expect(entities.length).toBe(5);
228241

229242
expect(entities[0].text).toBe('inside_tb');
230243
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
231244
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
232245

233-
expect(entities[3].text).toBe('insert_tb');
234-
expect(entities[3].entityContextType).toBe(EntityContextType.TABLE);
246+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
247+
expect(entities[1].text).toBe('');
248+
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
249+
250+
expect(entities[2].entityContextType).toBe(EntityContextType.TABLE);
251+
expect(entities[2].text).toBe('SELECT FROM inside_tb');
252+
expect(entities[2][AttrName.alias].text).toBe('subquery');
253+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
254+
255+
expect(entities[3].entityContextType).toBe(EntityContextType.QUERY_RESULT);
256+
expect(entities[3].text).toBe('col1, col2, country, state');
235257
expect(entities[3].belongStmt.isContainCaret).toBeTruthy();
258+
259+
expect(entities[4].text).toBe('insert_tb');
260+
expect(entities[4].entityContextType).toBe(EntityContextType.TABLE);
261+
expect(entities[4].belongStmt.isContainCaret).toBeTruthy();
236262
});
237263

238264
test('insert into from nested query with columns and trailing comma', () => {
@@ -279,15 +305,19 @@ describe('Hive SQL Syntax Suggestion with collect entity', () => {
279305
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
280306

281307
const entities = hive.getAllEntities(sql, pos);
282-
expect(entities.length).toBe(2);
308+
expect(entities.length).toBe(3);
283309

284310
expect(entities[0].text).toBe('origin_table');
285311
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
286312
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
287313

288-
expect(entities[1].text).toBe('derived_table');
289-
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE_CREATE);
314+
expect(entities[1].text).toBe('');
315+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
290316
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
317+
318+
expect(entities[2].text).toBe('derived_table');
319+
expect(entities[2].entityContextType).toBe(EntityContextType.TABLE_CREATE);
320+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
291321
});
292322

293323
test('create table as select with columns and trailing comma', () => {

test/parser/impala/suggestion/suggestionWithEntity.test.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,18 @@ describe('Impala SQL Syntax Suggestion with collect entity', () => {
7474
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
7575

7676
const entities = impala.getAllEntities(sql, pos);
77-
expect(entities.length).toBe(2);
78-
expect(entities[0].text).toBe('insert_tb');
77+
expect(entities.length).toBe(3);
78+
expect(entities[0].text).toBe('from_tb');
7979
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
8080
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
8181

82-
expect(entities[1].text).toBe('from_tb');
83-
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
82+
expect(entities[1].text).toBe('');
83+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
8484
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
85+
86+
expect(entities[2].text).toBe('insert_tb');
87+
expect(entities[2].entityContextType).toBe(EntityContextType.TABLE);
88+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
8589
});
8690

8791
test('insert into table as select with trailing comma', () => {
@@ -136,14 +140,18 @@ describe('Impala SQL Syntax Suggestion with collect entity', () => {
136140
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
137141

138142
const entities = impala.getAllEntities(sql, pos);
139-
expect(entities.length).toBe(2);
140-
expect(entities[0].text).toBe('sorted_census_data');
141-
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE_CREATE);
143+
expect(entities.length).toBe(3);
144+
expect(entities[0].text).toBe('unsorted_census_data');
145+
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
142146
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
143147

144-
expect(entities[1].text).toBe('unsorted_census_data');
145-
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
148+
expect(entities[1].text).toBe('');
149+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
146150
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
151+
152+
expect(entities[2].text).toBe('sorted_census_data');
153+
expect(entities[2].entityContextType).toBe(EntityContextType.TABLE_CREATE);
154+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
147155
});
148156

149157
test('create table as select with trailing comma', () => {

test/parser/mysql/suggestion/syntaxSuggestion.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ describe('MySQL Syntax Suggestion', () => {
653653
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);
654654

655655
expect(syntaxContextTypes).not.toBeUndefined();
656-
expect(syntaxContextTypes).toEqual([EntityContextType.FUNCTION, EntityContextType.COLUMN]);
656+
expect(syntaxContextTypes).toEqual([EntityContextType.COLUMN, EntityContextType.FUNCTION]);
657657
});
658658

659659
test('Select function or column', () => {

test/parser/postgresql/suggestion/suggestionWithEntity.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ describe('PostgreSql Syntax Suggestion with collect entity', () => {
2727
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
2828

2929
const entities = postgre.getAllEntities(sql, pos);
30-
expect(entities.length).toBe(1);
30+
expect(entities.length).toBe(2);
3131
expect(entities[0].text).toBe('my_db.tb');
3232
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
3333
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
34+
35+
expect(entities[1].text).toBe('');
36+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
37+
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
3438
});
3539

3640
test('select with columns with trailing comma', () => {
@@ -74,15 +78,19 @@ describe('PostgreSql Syntax Suggestion with collect entity', () => {
7478
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
7579

7680
const entities = postgre.getAllEntities(sql, pos);
77-
expect(entities.length).toBe(2);
81+
expect(entities.length).toBe(3);
7882

7983
expect(entities[0].text).toBe('from_tb');
8084
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
8185
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
8286

83-
expect(entities[1].text).toBe('insert_tb');
84-
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
87+
expect(entities[1].text).toBe('');
88+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
8589
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
90+
91+
expect(entities[2].text).toBe('insert_tb');
92+
expect(entities[2].entityContextType).toBe(EntityContextType.TABLE);
93+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
8694
});
8795

8896
test('insert into table as select with trailing comma', () => {
@@ -130,15 +138,19 @@ describe('PostgreSql Syntax Suggestion with collect entity', () => {
130138
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
131139

132140
const entities = postgre.getAllEntities(sql, pos);
133-
expect(entities.length).toBe(2);
141+
expect(entities.length).toBe(3);
134142

135143
expect(entities[0].text).toBe('unsorted_census_data');
136144
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
137145
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
138146

139-
expect(entities[1].text).toBe('sorted_census_data');
140-
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE_CREATE);
147+
expect(entities[1].text).toBe('');
148+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
141149
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
150+
151+
expect(entities[2].text).toBe('sorted_census_data');
152+
expect(entities[2].entityContextType).toBe(EntityContextType.TABLE_CREATE);
153+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
142154
});
143155

144156
test('create table as select with trailing comma', () => {

test/parser/postgresql/suggestion/syntaxSuggestion.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ describe('Postgre SQL Syntax Suggestion', () => {
11551155
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);
11561156

11571157
expect(syntaxContextTypes).not.toBeUndefined();
1158-
expect(syntaxContextTypes).toEqual([EntityContextType.FUNCTION, EntityContextType.COLUMN]);
1158+
expect(syntaxContextTypes).toEqual([EntityContextType.COLUMN, EntityContextType.FUNCTION]);
11591159
});
11601160

11611161
test('Select function or column', () => {

test/parser/spark/suggestion/suggestionWithEntity.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ describe('Spark SQL Syntax Suggestion with collect entity', () => {
2727
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
2828

2929
const entities = spark.getAllEntities(sql, pos);
30-
expect(entities.length).toBe(1);
30+
expect(entities.length).toBe(2);
3131
expect(entities[0].text).toBe('my_db.tb');
3232
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
3333
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
34+
35+
expect(entities[1].text).toBe('');
36+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
37+
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
3438
});
3539

3640
test('select with columns with trailing comma', () => {
@@ -69,15 +73,19 @@ describe('Spark SQL Syntax Suggestion with collect entity', () => {
6973
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
7074

7175
const entities = spark.getAllEntities(sql, pos);
72-
expect(entities.length).toBe(2);
76+
expect(entities.length).toBe(3);
7377

7478
expect(entities[0].text).toBe('from_tb');
7579
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
7680
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
7781

78-
expect(entities[1].text).toBe('insert_tb');
79-
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
82+
expect(entities[1].text).toBe('');
83+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
8084
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
85+
86+
expect(entities[2].text).toBe('insert_tb');
87+
expect(entities[2].entityContextType).toBe(EntityContextType.TABLE);
88+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
8189
});
8290

8391
test('insert into table as select with trailing comma', () => {
@@ -121,15 +129,19 @@ describe('Spark SQL Syntax Suggestion with collect entity', () => {
121129
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
122130

123131
const entities = spark.getAllEntities(sql, pos);
124-
expect(entities.length).toBe(2);
132+
expect(entities.length).toBe(3);
125133

126134
expect(entities[0].text).toBe('unsorted_census_data');
127135
expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
128136
expect(entities[0].belongStmt.isContainCaret).toBeTruthy();
129137

130-
expect(entities[1].text).toBe('sorted_census_data');
131-
expect(entities[1].entityContextType).toBe(EntityContextType.TABLE_CREATE);
138+
expect(entities[1].text).toBe('');
139+
expect(entities[1].entityContextType).toBe(EntityContextType.QUERY_RESULT);
132140
expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
141+
142+
expect(entities[2].text).toBe('sorted_census_data');
143+
expect(entities[2].entityContextType).toBe(EntityContextType.TABLE_CREATE);
144+
expect(entities[2].belongStmt.isContainCaret).toBeTruthy();
133145
});
134146

135147
test('create table as select with trailing comma', () => {

0 commit comments

Comments
 (0)