Skip to content
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 @@ -41,6 +41,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 @@ -127,6 +129,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
9 changes: 4 additions & 5 deletions test/parser/flink/suggestion/fixtures/tokenSuggestion.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
SELECT * FROM aa.bb;

USE
USE
;
CREATE
;
SHOW
;
CREATE TABLE IF NOT EXISTS
;
SHOW

CREATE TABLE tmp_table (col INT) WITH ('connector'='kafka');
58 changes: 57 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 @@ -93,4 +93,60 @@ describe('Flink SQL Token Suggestion', () => {
expect(suggestion).toContain('NOT');
expect(suggestion).toContain('NOT EXISTS');
});

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);
});
});

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);
});
});
});
Loading