Skip to content

Commit 297b2f9

Browse files
authored
feat(flink): implement suggestion support for table properties in CREATE TABLE (#417)
* feat(flink): implement suggestion support for table properties in CREATE TABLE * fix(suggestion): move SQL to fixtures * chore(sql): add EOL * feat(flink): implement suggestion support for table properties in CREATE TABLE # Conflicts: # test/parser/flink/suggestion/tokenSuggestion.test.ts * fix(suggestion): move SQL to fixtures * fix(syntaxSuggestion): resolve conflicts and move tests * fix: revert old changes * fix: revert old changes * fix: merge issues * fix: unit tests
1 parent a3e6d1e commit 297b2f9

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-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
@@ -45,6 +45,8 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
4545
FlinkSqlParser.RULE_columnName,
4646
FlinkSqlParser.RULE_columnNamePath,
4747
FlinkSqlParser.RULE_columnNameCreate,
48+
FlinkSqlParser.RULE_tablePropertyKey,
49+
FlinkSqlParser.RULE_tablePropertyValue,
4850
]);
4951

5052
protected get splitListener() {
@@ -142,6 +144,14 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
142144
}
143145
break;
144146
}
147+
case FlinkSqlParser.RULE_tablePropertyKey: {
148+
syntaxContextType = EntityContextType.TABLE_PROPERTY_KEY;
149+
break;
150+
}
151+
case FlinkSqlParser.RULE_tablePropertyValue: {
152+
syntaxContextType = EntityContextType.TABLE_PROPERTY_VALUE;
153+
break;
154+
}
145155
default:
146156
break;
147157
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ SELECT SUM(amount) FROM Orders GROUP BY length(users) HAVING SUM(amount) > 50;
4444

4545
SELECT * FROM Orders ORDER BY orderTime LIMIT length(order_id);
4646

47-
SELECT age CASE WHEN age < 18 THEN 1 ELSE 0 END AS is_minor FROM dt_catalog.dt_db.subscriptions;
47+
SELECT age CASE WHEN age < 18 THEN 1 ELSE 0 END AS is_minor FROM dt_catalog.dt_db.subscriptions;
48+
49+
CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,32 @@ describe('Flink SQL Syntax Suggestion', () => {
469469
expect(suggestion).not.toBeUndefined();
470470
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['age']);
471471
});
472+
473+
test('Create Statement table properties', () => {
474+
const scenarios = [
475+
{
476+
caretPosition: {
477+
lineNumber: 49,
478+
column: 45,
479+
},
480+
entityContextType: EntityContextType.TABLE_PROPERTY_KEY,
481+
},
482+
{
483+
caretPosition: {
484+
lineNumber: 49,
485+
column: 55,
486+
},
487+
entityContextType: EntityContextType.TABLE_PROPERTY_VALUE,
488+
},
489+
];
490+
491+
scenarios.forEach((scenario) => {
492+
const suggestion = flink.getSuggestionAtCaretPosition(
493+
commentOtherLine(syntaxSql, scenario.caretPosition.lineNumber),
494+
scenario.caretPosition
495+
)?.syntax;
496+
497+
expect(suggestion[0].syntaxContextType).toBe(scenario.entityContextType);
498+
});
499+
});
472500
});

0 commit comments

Comments
 (0)