Skip to content

feat(flink): implement suggestion support for table properties in CREATE TABLE #417

New issue

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

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

Already on GitHub? # to your account

Merged
merged 11 commits into from
May 16, 2025
4 changes: 4 additions & 0 deletions src/parser/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/parser/flink/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
FlinkSqlParser.RULE_columnName,
FlinkSqlParser.RULE_columnNamePath,
FlinkSqlParser.RULE_columnNameCreate,
FlinkSqlParser.RULE_tablePropertyKey,
FlinkSqlParser.RULE_tablePropertyValue,
]);

protected get splitListener() {
Expand Down Expand Up @@ -142,6 +144,14 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
}
break;
}
case FlinkSqlParser.RULE_tablePropertyKey: {
syntaxContextType = EntityContextType.TABLE_PROPERTY_KEY;
break;
}
case FlinkSqlParser.RULE_tablePropertyValue: {
syntaxContextType = EntityContextType.TABLE_PROPERTY_VALUE;
break;
}
default:
break;
}
Expand Down
4 changes: 3 additions & 1 deletion test/parser/flink/suggestion/fixtures/syntaxSuggestion.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ SELECT SUM(amount) FROM Orders GROUP BY length(users) HAVING SUM(amount) > 50;

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;
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');
28 changes: 28 additions & 0 deletions test/parser/flink/suggestion/syntaxSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,32 @@ describe('Flink SQL Syntax Suggestion', () => {
expect(suggestion).not.toBeUndefined();
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['age']);
});

test('Create Statement table properties', () => {
const scenarios = [
{
caretPosition: {
lineNumber: 49,
column: 45,
},
entityContextType: EntityContextType.TABLE_PROPERTY_KEY,
},
{
caretPosition: {
lineNumber: 49,
column: 55,
},
entityContextType: EntityContextType.TABLE_PROPERTY_VALUE,
},
];

scenarios.forEach((scenario) => {
const suggestion = flink.getSuggestionAtCaretPosition(
commentOtherLine(syntaxSql, scenario.caretPosition.lineNumber),
scenario.caretPosition
)?.syntax;

expect(suggestion[0].syntaxContextType).toBe(scenario.entityContextType);
});
});
});