Skip to content

Commit 608e7e5

Browse files
committed
feat(flink): implement suggestion support for table properties in CREATE TABLE
1 parent b788e1c commit 608e7e5

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/parser/common/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export enum EntityContextType {
4444
COLUMN = 'column',
4545
/** column name that will be created */
4646
COLUMN_CREATE = 'columnCreate',
47+
/** table property key when creating table*/
48+
TABLE_PROPERTY_KEY = 'tablePropertyKey',
49+
/** table property value when creating table*/
50+
TABLE_PROPERTY_VALUE = 'tablePropertyValue',
4751
}
4852

4953
/**

src/parser/flink/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
3131
FlinkSqlParser.RULE_functionNameCreate, // functionName that will be created
3232
FlinkSqlParser.RULE_columnName,
3333
FlinkSqlParser.RULE_columnNameCreate,
34+
FlinkSqlParser.RULE_tablePropertyKey,
35+
FlinkSqlParser.RULE_tablePropertyValue,
3436
]);
3537

3638
protected get splitListener() {
@@ -104,6 +106,14 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
104106
syntaxContextType = EntityContextType.COLUMN_CREATE;
105107
break;
106108
}
109+
case FlinkSqlParser.RULE_tablePropertyKey: {
110+
syntaxContextType = EntityContextType.TABLE_PROPERTY_KEY;
111+
break;
112+
}
113+
case FlinkSqlParser.RULE_tablePropertyValue: {
114+
syntaxContextType = EntityContextType.TABLE_PROPERTY_VALUE;
115+
break;
116+
}
107117
default:
108118
break;
109119
}

test/parser/flink/suggestion/tokenSuggestion.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import { FlinkSQL } from 'src/parser/flink';
4-
import { CaretPosition } from 'src/parser/common/types';
4+
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
55
import { commentOtherLine } from 'test/helper';
66

77
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
@@ -67,4 +67,33 @@ describe('Flink SQL Token Suggestion', () => {
6767
'JARS',
6868
]);
6969
});
70+
71+
test('Create Statement table properties', () => {
72+
const tokenSql = `CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');`;
73+
const scenarios = [
74+
{
75+
caretPosition: {
76+
lineNumber: 1,
77+
column: 45,
78+
},
79+
entityContextType: EntityContextType.TABLE_PROPERTY_KEY,
80+
},
81+
{
82+
caretPosition: {
83+
lineNumber: 1,
84+
column: 55,
85+
},
86+
entityContextType: EntityContextType.TABLE_PROPERTY_VALUE,
87+
},
88+
];
89+
90+
scenarios.forEach((scenario) => {
91+
const suggestion = flink.getSuggestionAtCaretPosition(
92+
tokenSql,
93+
scenario.caretPosition
94+
)?.syntax;
95+
96+
expect(suggestion[0].syntaxContextType).toBe(scenario.entityContextType);
97+
});
98+
});
7099
});

0 commit comments

Comments
 (0)