Skip to content

Commit d40a3d5

Browse files
committed
test: #438 sync suggestion no duplicate syntaxContextType
1 parent 3684ae7 commit d40a3d5

File tree

14 files changed

+262
-3
lines changed

14 files changed

+262
-3
lines changed

test/parser/flink/suggestion/fixtures/syntaxSuggestion.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ SELECT * FROM Orders ORDER BY orderTime LIMIT length(order_id);
4747
SELECT age CASE WHEN age < 18 THEN 1 ELSE 0 END AS is_minor FROM dt_catalog.dt_db.subscriptions;
4848

4949
CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');
50+
51+
SELECT FROM tb1;
52+
53+
SELECT age FROM tb1;

test/parser/flink/suggestion/syntaxSuggestion.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,39 @@ describe('Flink SQL Syntax Suggestion', () => {
498498
});
499499
});
500500

501+
test('Sync suggestion no duplicate syntaxContextType', () => {
502+
const pos: CaretPosition = {
503+
lineNumber: 51,
504+
column: 8,
505+
};
506+
const syntaxes = flink.getSuggestionAtCaretPosition(
507+
commentOtherLine(syntaxSql, pos.lineNumber),
508+
pos
509+
)?.syntax;
510+
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);
511+
512+
expect(syntaxContextTypes).not.toBeUndefined();
513+
expect(syntaxContextTypes).toEqual([EntityContextType.FUNCTION, EntityContextType.COLUMN]);
514+
});
515+
516+
test('Select function or column', () => {
517+
const pos: CaretPosition = {
518+
lineNumber: 53,
519+
column: 11,
520+
};
521+
const syntaxes = flink.getSuggestionAtCaretPosition(
522+
commentOtherLine(syntaxSql, pos.lineNumber),
523+
pos
524+
)?.syntax;
525+
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);
526+
527+
expect(wordRangesArr).not.toBeUndefined();
528+
expect(wordRangesArr.length).toBe(2);
529+
expect(
530+
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
531+
).toEqual([['age'], ['age']]);
532+
});
533+
501534
test('Syntax suggestion after a comment', () => {
502535
const sql = `-- the comment\nSELECT * FROM db.`;
503536
const pos: CaretPosition = {

test/parser/hive/suggestion/fixtures/syntaxSuggestion.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ SELECT a, COUNT(b) OVER (PARTITION BY c, d) FROM T;
5858

5959
SELECT a.* FROM a JOIN b ON (a.id = b.id AND a.department = b.department);
6060

61-
SELECT col1, col2, CASE WHEN month = 'January' THEN 2023 ELSE 2024 END AS year, CAST(day AS int) AS day FROM source_table;
61+
SELECT col1, col2, CASE WHEN month = 'January' THEN 2023 ELSE 2024 END AS year, CAST(day AS int) AS day FROM source_table;
62+
63+
SELECT FROM tb1;
64+
65+
SELECT age FROM tb1;

test/parser/hive/suggestion/syntaxSuggestion.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,39 @@ describe('Hive SQL Syntax Suggestion', () => {
592592
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['month']);
593593
});
594594

595+
test('Sync suggestion no duplicate syntaxContextType', () => {
596+
const pos: CaretPosition = {
597+
lineNumber: 63,
598+
column: 8,
599+
};
600+
const syntaxes = hive.getSuggestionAtCaretPosition(
601+
commentOtherLine(syntaxSql, pos.lineNumber),
602+
pos
603+
)?.syntax;
604+
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);
605+
606+
expect(syntaxContextTypes).not.toBeUndefined();
607+
expect(syntaxContextTypes).toEqual([EntityContextType.COLUMN, EntityContextType.FUNCTION]);
608+
});
609+
610+
test('Select function or column', () => {
611+
const pos: CaretPosition = {
612+
lineNumber: 65,
613+
column: 11,
614+
};
615+
const syntaxes = hive.getSuggestionAtCaretPosition(
616+
commentOtherLine(syntaxSql, pos.lineNumber),
617+
pos
618+
)?.syntax;
619+
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);
620+
621+
expect(wordRangesArr).not.toBeUndefined();
622+
expect(wordRangesArr.length).toBe(2);
623+
expect(
624+
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
625+
).toEqual([['age'], ['age']]);
626+
});
627+
595628
test('Syntax suggestion after a comment', () => {
596629
const sql = `-- the comment\nSELECT * FROM db.`;
597630
const pos: CaretPosition = {

test/parser/impala/suggestion/fixtures/syntaxSuggestion.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ ALTER TABLE my_table ADD COLUMN age INT COMMENT 'Updated Age';
4444

4545
CREATE TABLE kudu_no_partition_by_clause (id bigint PRIMARY KEY, s STRING, b BOOLEAN ) STORED AS KUDU;
4646

47-
CREATE TABLE PARTITIONS_YES PARTITIONED BY (YEAR, MONTH);
47+
CREATE TABLE PARTITIONS_YES PARTITIONED BY (YEAR, MONTH);
48+
49+
SELECT FROM tb1;
50+
51+
SELECT age FROM tb1;

test/parser/impala/suggestion/syntaxSuggestion.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,39 @@ describe('Impala SQL Syntax Suggestion', () => {
463463
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['YEAR']);
464464
});
465465

466+
test('Sync suggestion no duplicate syntaxContextType', () => {
467+
const pos: CaretPosition = {
468+
lineNumber: 49,
469+
column: 8,
470+
};
471+
const syntaxes = impala.getSuggestionAtCaretPosition(
472+
commentOtherLine(syntaxSql, pos.lineNumber),
473+
pos
474+
)?.syntax;
475+
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);
476+
477+
expect(syntaxContextTypes).not.toBeUndefined();
478+
expect(syntaxContextTypes).toEqual([EntityContextType.COLUMN, EntityContextType.FUNCTION]);
479+
});
480+
481+
test('Select function or column', () => {
482+
const pos: CaretPosition = {
483+
lineNumber: 51,
484+
column: 11,
485+
};
486+
const syntaxes = impala.getSuggestionAtCaretPosition(
487+
commentOtherLine(syntaxSql, pos.lineNumber),
488+
pos
489+
)?.syntax;
490+
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);
491+
492+
expect(wordRangesArr).not.toBeUndefined();
493+
expect(wordRangesArr.length).toBe(2);
494+
expect(
495+
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
496+
).toEqual([['age'], ['age']]);
497+
});
498+
466499
test('Syntax suggestion after a comment', () => {
467500
const sql = `-- the comment\nSELECT * FROM db.`;
468501
const pos: CaretPosition = {

test/parser/mysql/suggestion/fixtures/syntaxSuggestion.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ SELECT user, MAX(salary) FROM users where age = 10 GROUP BY length(user) HAVING
6060

6161
SELECT c.category_id FROM category c JOIN product p ON c.category_id = p.category_id;
6262

63-
SELECT score, CASE WHEN score >= 90 THEN 'A' ELSE 'F' END AS grade FROM students;
63+
SELECT score, CASE WHEN score >= 90 THEN 'A' ELSE 'F' END AS grade FROM students;
64+
65+
SELECT FROM tb1;
66+
67+
SELECT age FROM tb1;

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,39 @@ describe('MySQL Syntax Suggestion', () => {
641641
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['score']);
642642
});
643643

644+
test('Sync suggestion no duplicate syntaxContextType', () => {
645+
const pos: CaretPosition = {
646+
lineNumber: 65,
647+
column: 8,
648+
};
649+
const syntaxes = mysql.getSuggestionAtCaretPosition(
650+
commentOtherLine(syntaxSql, pos.lineNumber),
651+
pos
652+
)?.syntax;
653+
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);
654+
655+
expect(syntaxContextTypes).not.toBeUndefined();
656+
expect(syntaxContextTypes).toEqual([EntityContextType.FUNCTION, EntityContextType.COLUMN]);
657+
});
658+
659+
test('Select function or column', () => {
660+
const pos: CaretPosition = {
661+
lineNumber: 67,
662+
column: 11,
663+
};
664+
const syntaxes = mysql.getSuggestionAtCaretPosition(
665+
commentOtherLine(syntaxSql, pos.lineNumber),
666+
pos
667+
)?.syntax;
668+
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);
669+
670+
expect(wordRangesArr).not.toBeUndefined();
671+
expect(wordRangesArr.length).toBe(2);
672+
expect(
673+
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
674+
).toEqual([['age'], ['age']]);
675+
});
676+
644677
test('Syntax suggestion after a comment', () => {
645678
const sql = `-- the comment\nSELECT * FROM db.`;
646679
const pos: CaretPosition = {

test/parser/postgresql/suggestion/fixtures/syntaxSuggestion.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ VALUES (1, '3'), (3, 'sdsd') ORDER BY sort_expression ASC LIMIT id = 1;
8787
CREATE OR REPLACE RULE name AS ON SELECT TO table_name WHERE length(y+x) = 3 DO INSTEAD NOTHING;
8888

8989
WITH query_name (id) AS (SELECT id FROM table_expression) SELECT DISTINCT ON (col1) random() AS name1 FROM table_expression WHERE name1=name1 GROUP BY id HAVING sum(len+y) < interval '5 hours' WINDOW w AS (PARTITION BY depname ORDER BY salary DESC) EXCEPT (SELECT * FROM others) ORDER BY salary USING > NULLS FIRST OFFSET start FETCH NEXT ROW ONLY FOR KEY SHARE OF table_name NOWAIT;
90+
91+
SELECT FROM tb1;
92+
93+
SELECT age FROM tb1;

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,39 @@ describe('Postgre SQL Syntax Suggestion', () => {
11431143
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['depname']);
11441144
});
11451145

1146+
test('Sync suggestion no duplicate syntaxContextType', () => {
1147+
const pos: CaretPosition = {
1148+
lineNumber: 91,
1149+
column: 8,
1150+
};
1151+
const syntaxes = postgresql.getSuggestionAtCaretPosition(
1152+
commentOtherLine(syntaxSql, pos.lineNumber),
1153+
pos
1154+
)?.syntax;
1155+
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);
1156+
1157+
expect(syntaxContextTypes).not.toBeUndefined();
1158+
expect(syntaxContextTypes).toEqual([EntityContextType.FUNCTION, EntityContextType.COLUMN]);
1159+
});
1160+
1161+
test('Select function or column', () => {
1162+
const pos: CaretPosition = {
1163+
lineNumber: 93,
1164+
column: 11,
1165+
};
1166+
const syntaxes = postgresql.getSuggestionAtCaretPosition(
1167+
commentOtherLine(syntaxSql, pos.lineNumber),
1168+
pos
1169+
)?.syntax;
1170+
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);
1171+
1172+
expect(wordRangesArr).not.toBeUndefined();
1173+
expect(wordRangesArr.length).toBe(2);
1174+
expect(
1175+
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
1176+
).toEqual([['age'], ['age']]);
1177+
});
1178+
11461179
test('Syntax suggestion after a comment', () => {
11471180
const sql = `-- the comment\nSELECT * FROM db.`;
11481181
const pos: CaretPosition = {

0 commit comments

Comments
 (0)