Skip to content

Commit 13374e3

Browse files
committed
feat(flink): implement suggestion support for table properties in CREATE TABLE
1 parent 042477d commit 13374e3

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
@@ -41,6 +41,8 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
4141
FlinkSqlParser.RULE_functionNameCreate, // functionName that will be created
4242
FlinkSqlParser.RULE_columnName,
4343
FlinkSqlParser.RULE_columnNameCreate,
44+
FlinkSqlParser.RULE_tablePropertyKey,
45+
FlinkSqlParser.RULE_tablePropertyValue,
4446
]);
4547

4648
protected get splitListener() {
@@ -127,6 +129,14 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
127129
syntaxContextType = EntityContextType.COLUMN_CREATE;
128130
break;
129131
}
132+
case FlinkSqlParser.RULE_tablePropertyKey: {
133+
syntaxContextType = EntityContextType.TABLE_PROPERTY_KEY;
134+
break;
135+
}
136+
case FlinkSqlParser.RULE_tablePropertyValue: {
137+
syntaxContextType = EntityContextType.TABLE_PROPERTY_VALUE;
138+
break;
139+
}
130140
default:
131141
break;
132142
}

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');
@@ -93,4 +93,33 @@ describe('Flink SQL Token Suggestion', () => {
9393
expect(suggestion).toContain('NOT');
9494
expect(suggestion).toContain('NOT EXISTS');
9595
});
96+
97+
test('Create Statement table properties', () => {
98+
const tokenSql = `CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');`;
99+
const scenarios = [
100+
{
101+
caretPosition: {
102+
lineNumber: 1,
103+
column: 45,
104+
},
105+
entityContextType: EntityContextType.TABLE_PROPERTY_KEY,
106+
},
107+
{
108+
caretPosition: {
109+
lineNumber: 1,
110+
column: 55,
111+
},
112+
entityContextType: EntityContextType.TABLE_PROPERTY_VALUE,
113+
},
114+
];
115+
116+
scenarios.forEach((scenario) => {
117+
const suggestion = flink.getSuggestionAtCaretPosition(
118+
tokenSql,
119+
scenario.caretPosition
120+
)?.syntax;
121+
122+
expect(suggestion[0].syntaxContextType).toBe(scenario.entityContextType);
123+
});
124+
});
96125
});

0 commit comments

Comments
 (0)