From 608e7e51d718ec16fe9e7dff11e08c553a0509d1 Mon Sep 17 00:00:00 2001 From: Eduardas Kazakas Date: Mon, 27 Jan 2025 10:35:44 +0200 Subject: [PATCH 1/3] feat(flink): implement suggestion support for table properties in CREATE TABLE --- src/parser/common/types.ts | 4 +++ src/parser/flink/index.ts | 10 ++++++ .../flink/suggestion/tokenSuggestion.test.ts | 31 ++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/parser/common/types.ts b/src/parser/common/types.ts index 853673ce..20330305 100644 --- a/src/parser/common/types.ts +++ b/src/parser/common/types.ts @@ -44,6 +44,10 @@ export enum EntityContextType { COLUMN = 'column', /** column name that will be created */ COLUMN_CREATE = 'columnCreate', + /** table property key when creating table*/ + TABLE_PROPERTY_KEY = 'tablePropertyKey', + /** table property value when creating table*/ + TABLE_PROPERTY_VALUE = 'tablePropertyValue', } /** diff --git a/src/parser/flink/index.ts b/src/parser/flink/index.ts index eb727986..138666d2 100644 --- a/src/parser/flink/index.ts +++ b/src/parser/flink/index.ts @@ -31,6 +31,8 @@ export class FlinkSQL extends BasicSQL { 'JARS', ]); }); + + test('Create Statement table properties', () => { + const tokenSql = `CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');`; + const scenarios = [ + { + caretPosition: { + lineNumber: 1, + column: 45, + }, + entityContextType: EntityContextType.TABLE_PROPERTY_KEY, + }, + { + caretPosition: { + lineNumber: 1, + column: 55, + }, + entityContextType: EntityContextType.TABLE_PROPERTY_VALUE, + }, + ]; + + scenarios.forEach((scenario) => { + const suggestion = flink.getSuggestionAtCaretPosition( + tokenSql, + scenario.caretPosition + )?.syntax; + + expect(suggestion[0].syntaxContextType).toBe(scenario.entityContextType); + }); + }); }); From aef0b66fbef80da4105fbd894b949eaa00c7e148 Mon Sep 17 00:00:00 2001 From: Eduardas Kazakas Date: Thu, 13 Mar 2025 09:42:23 +0200 Subject: [PATCH 2/3] fix(suggestion): move SQL to fixtures --- test/parser/flink/suggestion/fixtures/tokenSuggestion.sql | 6 ++++-- test/parser/flink/suggestion/tokenSuggestion.test.ts | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/parser/flink/suggestion/fixtures/tokenSuggestion.sql b/test/parser/flink/suggestion/fixtures/tokenSuggestion.sql index b8c7ef55..795c807b 100644 --- a/test/parser/flink/suggestion/fixtures/tokenSuggestion.sql +++ b/test/parser/flink/suggestion/fixtures/tokenSuggestion.sql @@ -1,7 +1,9 @@ SELECT * FROM aa.bb; -USE +USE ; CREATE ; -SHOW \ No newline at end of file +SHOW + +CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka'); \ No newline at end of file diff --git a/test/parser/flink/suggestion/tokenSuggestion.test.ts b/test/parser/flink/suggestion/tokenSuggestion.test.ts index 83bb45da..f2395d8f 100644 --- a/test/parser/flink/suggestion/tokenSuggestion.test.ts +++ b/test/parser/flink/suggestion/tokenSuggestion.test.ts @@ -69,18 +69,17 @@ describe('Flink SQL Token Suggestion', () => { }); test('Create Statement table properties', () => { - const tokenSql = `CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');`; const scenarios = [ { caretPosition: { - lineNumber: 1, + lineNumber: 9, column: 45, }, entityContextType: EntityContextType.TABLE_PROPERTY_KEY, }, { caretPosition: { - lineNumber: 1, + lineNumber: 9, column: 55, }, entityContextType: EntityContextType.TABLE_PROPERTY_VALUE, @@ -89,7 +88,7 @@ describe('Flink SQL Token Suggestion', () => { scenarios.forEach((scenario) => { const suggestion = flink.getSuggestionAtCaretPosition( - tokenSql, + commentOtherLine(tokenSql, scenario.caretPosition.lineNumber), scenario.caretPosition )?.syntax; From 33b3f8252ed3b9643a246e14db90a24f215be20a Mon Sep 17 00:00:00 2001 From: Eduardas Kazakas Date: Thu, 13 Mar 2025 09:43:24 +0200 Subject: [PATCH 3/3] chore(sql): add EOL --- test/parser/flink/suggestion/fixtures/tokenSuggestion.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parser/flink/suggestion/fixtures/tokenSuggestion.sql b/test/parser/flink/suggestion/fixtures/tokenSuggestion.sql index 795c807b..dff1eb6c 100644 --- a/test/parser/flink/suggestion/fixtures/tokenSuggestion.sql +++ b/test/parser/flink/suggestion/fixtures/tokenSuggestion.sql @@ -6,4 +6,4 @@ CREATE ; SHOW -CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka'); \ No newline at end of file +CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');