Skip to content

Commit

Permalink
Improve/flink keywords (#195)
Browse files Browse the repository at this point in the history
* refactor: improve flinksql keywords rule

* test: correct flink sql unit test
  • Loading branch information
HaydenOrz authored Oct 30, 2023
1 parent 887de81 commit 21dcb3f
Show file tree
Hide file tree
Showing 12 changed files with 11,618 additions and 9,832 deletions.
902 changes: 521 additions & 381 deletions src/grammar/flinksql/FlinkSqlLexer.g4

Large diffs are not rendered by default.

486 changes: 110 additions & 376 deletions src/grammar/flinksql/FlinkSqlParser.g4

Large diffs are not rendered by default.

1,405 changes: 899 additions & 506 deletions src/lib/flinksql/FlinkSqlLexer.interp

Large diffs are not rendered by default.

1,882 changes: 1,072 additions & 810 deletions src/lib/flinksql/FlinkSqlLexer.tokens

Large diffs are not rendered by default.

5,847 changes: 3,478 additions & 2,369 deletions src/lib/flinksql/FlinkSqlLexer.ts

Large diffs are not rendered by default.

966 changes: 613 additions & 353 deletions src/lib/flinksql/FlinkSqlParser.interp

Large diffs are not rendered by default.

1,882 changes: 1,072 additions & 810 deletions src/lib/flinksql/FlinkSqlParser.tokens

Large diffs are not rendered by default.

8,013 changes: 3,828 additions & 4,185 deletions src/lib/flinksql/FlinkSqlParser.ts

Large diffs are not rendered by default.

38 changes: 14 additions & 24 deletions src/lib/flinksql/FlinkSqlParserListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { SubscriptContext } from "./FlinkSqlParser";
import { ColumnReferenceContext } from "./FlinkSqlParser";
import { DereferenceContext } from "./FlinkSqlParser";
import { ParenthesizedExpressionContext } from "./FlinkSqlParser";
import { DateFunctionExpressionContext } from "./FlinkSqlParser";
import { ErrorIdentContext } from "./FlinkSqlParser";
import { RealIdentContext } from "./FlinkSqlParser";
import { IdentityTransformContext } from "./FlinkSqlParser";
Expand Down Expand Up @@ -181,7 +182,6 @@ import { MultiUnitsIntervalContext } from "./FlinkSqlParser";
import { ErrorCapturingUnitToUnitIntervalContext } from "./FlinkSqlParser";
import { UnitToUnitIntervalContext } from "./FlinkSqlParser";
import { IntervalValueContext } from "./FlinkSqlParser";
import { ColumnAliasContext } from "./FlinkSqlParser";
import { TableAliasContext } from "./FlinkSqlParser";
import { ErrorCapturingIdentifierContext } from "./FlinkSqlParser";
import { ErrorCapturingIdentifierExtraContext } from "./FlinkSqlParser";
Expand Down Expand Up @@ -222,7 +222,6 @@ import { TimePointUnitContext } from "./FlinkSqlParser";
import { TimeIntervalUnitContext } from "./FlinkSqlParser";
import { ReservedKeywordsUsedAsFuncParamContext } from "./FlinkSqlParser";
import { ReservedKeywordsUsedAsFuncNameContext } from "./FlinkSqlParser";
import { ReservedKeywordsContext } from "./FlinkSqlParser";
import { NonReservedKeywordsContext } from "./FlinkSqlParser";


Expand Down Expand Up @@ -517,6 +516,19 @@ export interface FlinkSqlParserListener extends ParseTreeListener {
*/
exitParenthesizedExpression?: (ctx: ParenthesizedExpressionContext) => void;

/**
* Enter a parse tree produced by the `dateFunctionExpression`
* labeled alternative in `FlinkSqlParser.primaryExpression`.
* @param ctx the parse tree
*/
enterDateFunctionExpression?: (ctx: DateFunctionExpressionContext) => void;
/**
* Exit a parse tree produced by the `dateFunctionExpression`
* labeled alternative in `FlinkSqlParser.primaryExpression`.
* @param ctx the parse tree
*/
exitDateFunctionExpression?: (ctx: DateFunctionExpressionContext) => void;

/**
* Enter a parse tree produced by the `errorIdent`
* labeled alternative in `FlinkSqlParser.errorCapturingIdentifierExtra`.
Expand Down Expand Up @@ -2251,17 +2263,6 @@ export interface FlinkSqlParserListener extends ParseTreeListener {
*/
exitIntervalValue?: (ctx: IntervalValueContext) => void;

/**
* Enter a parse tree produced by `FlinkSqlParser.columnAlias`.
* @param ctx the parse tree
*/
enterColumnAlias?: (ctx: ColumnAliasContext) => void;
/**
* Exit a parse tree produced by `FlinkSqlParser.columnAlias`.
* @param ctx the parse tree
*/
exitColumnAlias?: (ctx: ColumnAliasContext) => void;

/**
* Enter a parse tree produced by `FlinkSqlParser.tableAlias`.
* @param ctx the parse tree
Expand Down Expand Up @@ -2702,17 +2703,6 @@ export interface FlinkSqlParserListener extends ParseTreeListener {
*/
exitReservedKeywordsUsedAsFuncName?: (ctx: ReservedKeywordsUsedAsFuncNameContext) => void;

/**
* Enter a parse tree produced by `FlinkSqlParser.reservedKeywords`.
* @param ctx the parse tree
*/
enterReservedKeywords?: (ctx: ReservedKeywordsContext) => void;
/**
* Exit a parse tree produced by `FlinkSqlParser.reservedKeywords`.
* @param ctx the parse tree
*/
exitReservedKeywords?: (ctx: ReservedKeywordsContext) => void;

/**
* Enter a parse tree produced by `FlinkSqlParser.nonReservedKeywords`.
* @param ctx the parse tree
Expand Down
25 changes: 9 additions & 16 deletions src/lib/flinksql/FlinkSqlParserVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { SubscriptContext } from "./FlinkSqlParser";
import { ColumnReferenceContext } from "./FlinkSqlParser";
import { DereferenceContext } from "./FlinkSqlParser";
import { ParenthesizedExpressionContext } from "./FlinkSqlParser";
import { DateFunctionExpressionContext } from "./FlinkSqlParser";
import { ErrorIdentContext } from "./FlinkSqlParser";
import { RealIdentContext } from "./FlinkSqlParser";
import { IdentityTransformContext } from "./FlinkSqlParser";
Expand Down Expand Up @@ -181,7 +182,6 @@ import { MultiUnitsIntervalContext } from "./FlinkSqlParser";
import { ErrorCapturingUnitToUnitIntervalContext } from "./FlinkSqlParser";
import { UnitToUnitIntervalContext } from "./FlinkSqlParser";
import { IntervalValueContext } from "./FlinkSqlParser";
import { ColumnAliasContext } from "./FlinkSqlParser";
import { TableAliasContext } from "./FlinkSqlParser";
import { ErrorCapturingIdentifierContext } from "./FlinkSqlParser";
import { ErrorCapturingIdentifierExtraContext } from "./FlinkSqlParser";
Expand Down Expand Up @@ -222,7 +222,6 @@ import { TimePointUnitContext } from "./FlinkSqlParser";
import { TimeIntervalUnitContext } from "./FlinkSqlParser";
import { ReservedKeywordsUsedAsFuncParamContext } from "./FlinkSqlParser";
import { ReservedKeywordsUsedAsFuncNameContext } from "./FlinkSqlParser";
import { ReservedKeywordsContext } from "./FlinkSqlParser";
import { NonReservedKeywordsContext } from "./FlinkSqlParser";


Expand Down Expand Up @@ -410,6 +409,14 @@ export interface FlinkSqlParserVisitor<Result> extends ParseTreeVisitor<Result>
*/
visitParenthesizedExpression?: (ctx: ParenthesizedExpressionContext) => Result;

/**
* Visit a parse tree produced by the `dateFunctionExpression`
* labeled alternative in `FlinkSqlParser.primaryExpression`.
* @param ctx the parse tree
* @return the visitor result
*/
visitDateFunctionExpression?: (ctx: DateFunctionExpressionContext) => Result;

/**
* Visit a parse tree produced by the `errorIdent`
* labeled alternative in `FlinkSqlParser.errorCapturingIdentifierExtra`.
Expand Down Expand Up @@ -1511,13 +1518,6 @@ export interface FlinkSqlParserVisitor<Result> extends ParseTreeVisitor<Result>
*/
visitIntervalValue?: (ctx: IntervalValueContext) => Result;

/**
* Visit a parse tree produced by `FlinkSqlParser.columnAlias`.
* @param ctx the parse tree
* @return the visitor result
*/
visitColumnAlias?: (ctx: ColumnAliasContext) => Result;

/**
* Visit a parse tree produced by `FlinkSqlParser.tableAlias`.
* @param ctx the parse tree
Expand Down Expand Up @@ -1798,13 +1798,6 @@ export interface FlinkSqlParserVisitor<Result> extends ParseTreeVisitor<Result>
*/
visitReservedKeywordsUsedAsFuncName?: (ctx: ReservedKeywordsUsedAsFuncNameContext) => Result;

/**
* Visit a parse tree produced by `FlinkSqlParser.reservedKeywords`.
* @param ctx the parse tree
* @return the visitor result
*/
visitReservedKeywords?: (ctx: ReservedKeywordsContext) => Result;

/**
* Visit a parse tree produced by `FlinkSqlParser.nonReservedKeywords`.
* @param ctx the parse tree
Expand Down
2 changes: 1 addition & 1 deletion test/parser/flinksql/suggestion/tokenSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('Flink SQL Token Suggestion', () => {
'CURRENT',
'CATALOGS',
'DATABASES',
'JARS',
'VIEWS',
'JARS',
]);
});
});
2 changes: 1 addition & 1 deletion test/parser/flinksql/syntax/fixtures/createTable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ CREATE TABLE catalog1.db1.table1 (
attr17 MAP<INT, BIGINT>,
name1 VARCHAR(64),
message ROW<data ROW<UPO_TIMESTAMP VARCHAR(20)>>,
raw RAW('class', 'snapshot')
`raw` RAW('class', 'snapshot')
) WITH ('connector' = 'kafka');

CREATE TABLE IF NOT EXISTS tbl1 (
Expand Down

0 comments on commit 21dcb3f

Please sign in to comment.