Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -31,6 +31,8 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
FlinkSqlParser.RULE_functionNameCreate, // functionName that will be created
FlinkSqlParser.RULE_columnName,
FlinkSqlParser.RULE_columnNameCreate,
FlinkSqlParser.RULE_tablePropertyKey,
FlinkSqlParser.RULE_tablePropertyValue,
]);

protected get splitListener() {
Expand Down Expand Up @@ -104,6 +106,14 @@ export class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlPa
syntaxContextType = EntityContextType.COLUMN_CREATE;
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
6 changes: 4 additions & 2 deletions test/parser/flink/suggestion/fixtures/tokenSuggestion.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
SELECT * FROM aa.bb;

USE
USE
;
CREATE
;
SHOW
SHOW

CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');
30 changes: 29 additions & 1 deletion test/parser/flink/suggestion/tokenSuggestion.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import { FlinkSQL } from 'src/parser/flink';
import { CaretPosition } from 'src/parser/common/types';
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
import { commentOtherLine } from 'test/helper';

const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
Expand Down Expand Up @@ -67,4 +67,32 @@ describe('Flink SQL Token Suggestion', () => {
'JARS',
]);
});

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

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

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