Skip to content

fix: #438 syntaxContextType not duplicate #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/parser/flink/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
break;
}

if (syntaxContextType) {
if (
syntaxContextType &&
!originalSyntaxSuggestions.some(
(syn) => syn.syntaxContextType === syntaxContextType
)
) {
originalSyntaxSuggestions.push({
syntaxContextType,
wordRanges: tokenRanges,
Expand Down
7 changes: 6 additions & 1 deletion src/parser/hive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ export class HiveSQL extends BasicSQL<HiveSqlLexer, ProgramContext, HiveSqlParse
break;
}

if (syntaxContextType) {
if (
syntaxContextType &&
!originalSyntaxSuggestions.some(
(syn) => syn.syntaxContextType === syntaxContextType
)
) {
originalSyntaxSuggestions.push({
syntaxContextType,
wordRanges: tokenRanges,
Expand Down
7 changes: 6 additions & 1 deletion src/parser/impala/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ export class ImpalaSQL extends BasicSQL<ImpalaSqlLexer, ProgramContext, ImpalaSq
break;
}

if (syntaxContextType) {
if (
syntaxContextType &&
!originalSyntaxSuggestions.some(
(syn) => syn.syntaxContextType === syntaxContextType
)
) {
originalSyntaxSuggestions.push({
syntaxContextType,
wordRanges: tokenRanges,
Expand Down
7 changes: 6 additions & 1 deletion src/parser/mysql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ export class MySQL extends BasicSQL<MySqlLexer, ProgramContext, MySqlParser> {
break;
}

if (syntaxContextType) {
if (
syntaxContextType &&
!originalSyntaxSuggestions.some(
(syn) => syn.syntaxContextType === syntaxContextType
)
) {
originalSyntaxSuggestions.push({
syntaxContextType,
wordRanges: tokenRanges,
Expand Down
7 changes: 6 additions & 1 deletion src/parser/postgresql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ export class PostgreSQL extends BasicSQL<PostgreSqlLexer, ProgramContext, Postgr
break;
}

if (syntaxContextType) {
if (
syntaxContextType &&
!originalSyntaxSuggestions.some(
(syn) => syn.syntaxContextType === syntaxContextType
)
) {
originalSyntaxSuggestions.push({
syntaxContextType,
wordRanges: tokenRanges,
Expand Down
7 changes: 6 additions & 1 deletion src/parser/spark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ export class SparkSQL extends BasicSQL<SparkSqlLexer, ProgramContext, SparkSqlPa
break;
}

if (syntaxContextType) {
if (
syntaxContextType &&
!originalSyntaxSuggestions.some(
(syn) => syn.syntaxContextType === syntaxContextType
)
) {
originalSyntaxSuggestions.push({
syntaxContextType,
wordRanges: tokenRanges,
Expand Down
7 changes: 6 additions & 1 deletion src/parser/trino/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ export class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, TrinoSqlPa
break;
}

if (syntaxContextType) {
if (
syntaxContextType &&
!originalSyntaxSuggestions.some(
(syn) => syn.syntaxContextType === syntaxContextType
)
) {
originalSyntaxSuggestions.push({
syntaxContextType,
wordRanges: tokenRanges,
Expand Down
4 changes: 4 additions & 0 deletions test/parser/flink/suggestion/fixtures/syntaxSuggestion.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ SELECT * FROM Orders ORDER BY orderTime LIMIT length(order_id);
SELECT age CASE WHEN age < 18 THEN 1 ELSE 0 END AS is_minor FROM dt_catalog.dt_db.subscriptions;

CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');

SELECT FROM tb1;

SELECT age FROM tb1;
33 changes: 33 additions & 0 deletions test/parser/flink/suggestion/syntaxSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,39 @@ describe('Flink SQL Syntax Suggestion', () => {
});
});

test('Sync suggestion no duplicate syntaxContextType', () => {
const pos: CaretPosition = {
lineNumber: 51,
column: 8,
};
const syntaxes = flink.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);

expect(syntaxContextTypes).not.toBeUndefined();
expect(syntaxContextTypes).toEqual([EntityContextType.FUNCTION, EntityContextType.COLUMN]);
});

test('Select function or column', () => {
const pos: CaretPosition = {
lineNumber: 53,
column: 11,
};
const syntaxes = flink.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);

expect(wordRangesArr).not.toBeUndefined();
expect(wordRangesArr.length).toBe(2);
expect(
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
).toEqual([['age'], ['age']]);
});

test('Syntax suggestion after a comment', () => {
const sql = `-- the comment\nSELECT * FROM db.`;
const pos: CaretPosition = {
Expand Down
6 changes: 5 additions & 1 deletion test/parser/hive/suggestion/fixtures/syntaxSuggestion.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ SELECT a, COUNT(b) OVER (PARTITION BY c, d) FROM T;

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

SELECT col1, col2, CASE WHEN month = 'January' THEN 2023 ELSE 2024 END AS year, CAST(day AS int) AS day FROM source_table;
SELECT col1, col2, CASE WHEN month = 'January' THEN 2023 ELSE 2024 END AS year, CAST(day AS int) AS day FROM source_table;

SELECT FROM tb1;

SELECT age FROM tb1;
33 changes: 33 additions & 0 deletions test/parser/hive/suggestion/syntaxSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,39 @@ describe('Hive SQL Syntax Suggestion', () => {
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['month']);
});

test('Sync suggestion no duplicate syntaxContextType', () => {
const pos: CaretPosition = {
lineNumber: 63,
column: 8,
};
const syntaxes = hive.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);

expect(syntaxContextTypes).not.toBeUndefined();
expect(syntaxContextTypes).toEqual([EntityContextType.COLUMN, EntityContextType.FUNCTION]);
});

test('Select function or column', () => {
const pos: CaretPosition = {
lineNumber: 65,
column: 11,
};
const syntaxes = hive.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);

expect(wordRangesArr).not.toBeUndefined();
expect(wordRangesArr.length).toBe(2);
expect(
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
).toEqual([['age'], ['age']]);
});

test('Syntax suggestion after a comment', () => {
const sql = `-- the comment\nSELECT * FROM db.`;
const pos: CaretPosition = {
Expand Down
6 changes: 5 additions & 1 deletion test/parser/impala/suggestion/fixtures/syntaxSuggestion.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ ALTER TABLE my_table ADD COLUMN age INT COMMENT 'Updated Age';

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

CREATE TABLE PARTITIONS_YES PARTITIONED BY (YEAR, MONTH);
CREATE TABLE PARTITIONS_YES PARTITIONED BY (YEAR, MONTH);

SELECT FROM tb1;

SELECT age FROM tb1;
33 changes: 33 additions & 0 deletions test/parser/impala/suggestion/syntaxSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,39 @@ describe('Impala SQL Syntax Suggestion', () => {
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['YEAR']);
});

test('Sync suggestion no duplicate syntaxContextType', () => {
const pos: CaretPosition = {
lineNumber: 49,
column: 8,
};
const syntaxes = impala.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);

expect(syntaxContextTypes).not.toBeUndefined();
expect(syntaxContextTypes).toEqual([EntityContextType.COLUMN, EntityContextType.FUNCTION]);
});

test('Select function or column', () => {
const pos: CaretPosition = {
lineNumber: 51,
column: 11,
};
const syntaxes = impala.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);

expect(wordRangesArr).not.toBeUndefined();
expect(wordRangesArr.length).toBe(2);
expect(
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
).toEqual([['age'], ['age']]);
});

test('Syntax suggestion after a comment', () => {
const sql = `-- the comment\nSELECT * FROM db.`;
const pos: CaretPosition = {
Expand Down
6 changes: 5 additions & 1 deletion test/parser/mysql/suggestion/fixtures/syntaxSuggestion.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ SELECT user, MAX(salary) FROM users where age = 10 GROUP BY length(user) HAVING

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

SELECT score, CASE WHEN score >= 90 THEN 'A' ELSE 'F' END AS grade FROM students;
SELECT score, CASE WHEN score >= 90 THEN 'A' ELSE 'F' END AS grade FROM students;

SELECT FROM tb1;

SELECT age FROM tb1;
33 changes: 33 additions & 0 deletions test/parser/mysql/suggestion/syntaxSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,39 @@ describe('MySQL Syntax Suggestion', () => {
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['score']);
});

test('Sync suggestion no duplicate syntaxContextType', () => {
const pos: CaretPosition = {
lineNumber: 65,
column: 8,
};
const syntaxes = mysql.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);

expect(syntaxContextTypes).not.toBeUndefined();
expect(syntaxContextTypes).toEqual([EntityContextType.FUNCTION, EntityContextType.COLUMN]);
});

test('Select function or column', () => {
const pos: CaretPosition = {
lineNumber: 67,
column: 11,
};
const syntaxes = mysql.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);

expect(wordRangesArr).not.toBeUndefined();
expect(wordRangesArr.length).toBe(2);
expect(
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
).toEqual([['age'], ['age']]);
});

test('Syntax suggestion after a comment', () => {
const sql = `-- the comment\nSELECT * FROM db.`;
const pos: CaretPosition = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ VALUES (1, '3'), (3, 'sdsd') ORDER BY sort_expression ASC LIMIT id = 1;
CREATE OR REPLACE RULE name AS ON SELECT TO table_name WHERE length(y+x) = 3 DO INSTEAD NOTHING;

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;

SELECT FROM tb1;

SELECT age FROM tb1;
33 changes: 33 additions & 0 deletions test/parser/postgresql/suggestion/syntaxSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,39 @@ describe('Postgre SQL Syntax Suggestion', () => {
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['depname']);
});

test('Sync suggestion no duplicate syntaxContextType', () => {
const pos: CaretPosition = {
lineNumber: 91,
column: 8,
};
const syntaxes = postgresql.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);

expect(syntaxContextTypes).not.toBeUndefined();
expect(syntaxContextTypes).toEqual([EntityContextType.FUNCTION, EntityContextType.COLUMN]);
});

test('Select function or column', () => {
const pos: CaretPosition = {
lineNumber: 93,
column: 11,
};
const syntaxes = postgresql.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);

expect(wordRangesArr).not.toBeUndefined();
expect(wordRangesArr.length).toBe(2);
expect(
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
).toEqual([['age'], ['age']]);
});

test('Syntax suggestion after a comment', () => {
const sql = `-- the comment\nSELECT * FROM db.`;
const pos: CaretPosition = {
Expand Down
4 changes: 4 additions & 0 deletions test/parser/spark/suggestion/fixtures/syntaxSuggestion.sql
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ INSERT OVERWRITE students PARTITION (student_id = 222222) SELECT name, address F
SELECT id, name, employee.deptno, deptname FROM employee FULL JOIN department ON employee.deptno = department.deptno;

SELECT city, sum(quantity) AS sum FROM dealer GROUP BY sum(city) HAVING max(quantity) > 15;

SELECT FROM tb1;

SELECT age FROM tb1;
33 changes: 33 additions & 0 deletions test/parser/spark/suggestion/syntaxSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,39 @@ describe('Spark SQL Syntax Suggestion', () => {
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['quantity']);
});

test('Sync suggestion no duplicate syntaxContextType', () => {
const pos: CaretPosition = {
lineNumber: 79,
column: 8,
};
const syntaxes = spark.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const syntaxContextTypes = syntaxes?.map((syn) => syn.syntaxContextType);

expect(syntaxContextTypes).not.toBeUndefined();
expect(syntaxContextTypes).toEqual([EntityContextType.COLUMN, EntityContextType.FUNCTION]);
});

test('Select function or column', () => {
const pos: CaretPosition = {
lineNumber: 81,
column: 11,
};
const syntaxes = spark.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, pos.lineNumber),
pos
)?.syntax;
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);

expect(wordRangesArr).not.toBeUndefined();
expect(wordRangesArr.length).toBe(2);
expect(
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
).toEqual([['age'], ['age']]);
});

test('Syntax suggestion after a comment', () => {
const sql = `-- the comment\nSELECT * FROM db.`;
const pos: CaretPosition = {
Expand Down
Loading