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(flinksql): collect comment, type attribute for entity #319

Merged
merged 11 commits into from
Jul 5, 2024
41 changes: 20 additions & 21 deletions src/grammar/flink/FlinkSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ createTable
simpleCreateTable
: KW_CREATE KW_TEMPORARY? KW_TABLE ifNotExists? tablePathCreate LR_BRACKET columnOptionDefinition (
COMMA columnOptionDefinition
)* (COMMA watermarkDefinition)? (COMMA tableConstraint)? (COMMA selfDefinitionClause)? RR_BRACKET commentSpec? partitionDefinition? withOption
likeDefinition?
)* (COMMA watermarkDefinition)? (COMMA tableConstraint)? (COMMA selfDefinitionClause)? RR_BRACKET (
KW_COMMENT comment=STRING_LITERAL
)? partitionDefinition? withOption likeDefinition?
;

/*
Expand All @@ -175,7 +176,7 @@ columnOptionDefinition
;

physicalColumnDefinition
: columnNameCreate columnType columnConstraint? commentSpec?
: columnNameCreate columnType columnConstraint? (KW_COMMENT comment=STRING_LITERAL)?
;

columnNameCreate
Expand All @@ -193,8 +194,8 @@ columnNameList
;

columnType
: typeName=(KW_DATE | KW_BOOLEAN | KW_NULL)
| typeName=(
: colType=(KW_DATE | KW_BOOLEAN | KW_NULL)
| colType=(
KW_CHAR
| KW_VARCHAR
| KW_STRING
Expand All @@ -210,12 +211,12 @@ columnType
| KW_TIMESTAMP_LTZ
| KW_DATETIME
) lengthOneDimension?
| typeName=KW_TIMESTAMP lengthOneDimension? ((KW_WITHOUT | KW_WITH) KW_LOCAL? KW_TIME KW_ZONE)?
| typeName=(KW_DECIMAL | KW_DEC | KW_NUMERIC | KW_FLOAT | KW_DOUBLE) lengthTwoOptionalDimension?
| type=(KW_ARRAY | KW_MULTISET) lengthOneTypeDimension?
| type=KW_MAP mapTypeDimension?
| type=KW_ROW rowTypeDimension?
| type=KW_RAW lengthTwoStringDimension?
| colType=KW_TIMESTAMP lengthOneDimension? ((KW_WITHOUT | KW_WITH) KW_LOCAL? KW_TIME KW_ZONE)?
| colType=(KW_DECIMAL | KW_DEC | KW_NUMERIC | KW_FLOAT | KW_DOUBLE) lengthTwoOptionalDimension?
| colType=(KW_ARRAY | KW_MULTISET) lengthOneTypeDimension?
| colType=KW_MAP mapTypeDimension?
| colType=KW_ROW rowTypeDimension?
| colType=KW_RAW lengthTwoStringDimension?
;

lengthOneDimension
Expand Down Expand Up @@ -247,10 +248,6 @@ columnConstraint
| KW_NOT? KW_NULL
;

commentSpec
LuckyFBB marked this conversation as resolved.
Show resolved Hide resolved
: KW_COMMENT STRING_LITERAL
;

metadataColumnDefinition
: columnNameCreate columnType KW_METADATA (KW_FROM metadataKey)? KW_VIRTUAL?
;
Expand All @@ -260,7 +257,7 @@ metadataKey
;

computedColumnDefinition
: columnNameCreate KW_AS computedColumnExpression commentSpec?
: columnNameCreate KW_AS computedColumnExpression (KW_COMMENT comment=STRING_LITERAL)?
;

// 计算表达式
Expand Down Expand Up @@ -316,11 +313,13 @@ createCatalog
;

createDatabase
: KW_CREATE KW_DATABASE ifNotExists? databasePathCreate commentSpec? withOption
: KW_CREATE KW_DATABASE ifNotExists? databasePathCreate (KW_COMMENT comment=STRING_LITERAL)? withOption
;

createView
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? viewPathCreate columnNameList? commentSpec? KW_AS queryStatement
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? viewPathCreate columnNameList? (
KW_COMMENT comment=STRING_LITERAL
)? KW_AS queryStatement
;

createFunction
Expand Down Expand Up @@ -513,8 +512,8 @@ tableReference
;

tablePrimary
: KW_TABLE? tablePath systemTimePeriod? (KW_AS? correlationName)?
| viewPath systemTimePeriod? (KW_AS? correlationName)?
: KW_TABLE? tablePath systemTimePeriod?
| viewPath systemTimePeriod?
| KW_LATERAL KW_TABLE LR_BRACKET functionName LR_BRACKET functionParam (COMMA functionParam)* RR_BRACKET RR_BRACKET
| KW_LATERAL? LR_BRACKET queryStatement RR_BRACKET
| KW_UNNEST LR_BRACKET expression RR_BRACKET
Expand Down Expand Up @@ -834,7 +833,7 @@ intervalValue
;

tableAlias
: KW_AS? identifier identifierList?
: KW_AS? alias=identifier identifierList?
;

errorCapturingIdentifier
Expand Down
3 changes: 1 addition & 2 deletions src/lib/flink/FlinkSqlParser.interp

Large diffs are not rendered by default.

4,669 changes: 2,294 additions & 2,375 deletions src/lib/flink/FlinkSqlParser.ts

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions src/lib/flink/FlinkSqlParserListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import { LengthOneTypeDimensionContext } from "./FlinkSqlParser.js";
import { MapTypeDimensionContext } from "./FlinkSqlParser.js";
import { RowTypeDimensionContext } from "./FlinkSqlParser.js";
import { ColumnConstraintContext } from "./FlinkSqlParser.js";
import { CommentSpecContext } from "./FlinkSqlParser.js";
import { MetadataColumnDefinitionContext } from "./FlinkSqlParser.js";
import { MetadataKeyContext } from "./FlinkSqlParser.js";
import { ComputedColumnDefinitionContext } from "./FlinkSqlParser.js";
Expand Down Expand Up @@ -588,16 +587,6 @@ export class FlinkSqlParserListener implements ParseTreeListener {
* @param ctx the parse tree
*/
exitColumnConstraint?: (ctx: ColumnConstraintContext) => void;
/**
* Enter a parse tree produced by `FlinkSqlParser.commentSpec`.
* @param ctx the parse tree
*/
enterCommentSpec?: (ctx: CommentSpecContext) => void;
/**
* Exit a parse tree produced by `FlinkSqlParser.commentSpec`.
* @param ctx the parse tree
*/
exitCommentSpec?: (ctx: CommentSpecContext) => void;
/**
* Enter a parse tree produced by `FlinkSqlParser.metadataColumnDefinition`.
* @param ctx the parse tree
Expand Down
7 changes: 0 additions & 7 deletions src/lib/flink/FlinkSqlParserVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import { LengthOneTypeDimensionContext } from "./FlinkSqlParser.js";
import { MapTypeDimensionContext } from "./FlinkSqlParser.js";
import { RowTypeDimensionContext } from "./FlinkSqlParser.js";
import { ColumnConstraintContext } from "./FlinkSqlParser.js";
import { CommentSpecContext } from "./FlinkSqlParser.js";
import { MetadataColumnDefinitionContext } from "./FlinkSqlParser.js";
import { MetadataKeyContext } from "./FlinkSqlParser.js";
import { ComputedColumnDefinitionContext } from "./FlinkSqlParser.js";
Expand Down Expand Up @@ -447,12 +446,6 @@ export class FlinkSqlParserVisitor<Result> extends AbstractParseTreeVisitor<Resu
* @return the visitor result
*/
visitColumnConstraint?: (ctx: ColumnConstraintContext) => Result;
/**
* Visit a parse tree produced by `FlinkSqlParser.commentSpec`.
* @param ctx the parse tree
* @return the visitor result
*/
visitCommentSpec?: (ctx: CommentSpecContext) => Result;
/**
* Visit a parse tree produced by `FlinkSqlParser.metadataColumnDefinition`.
* @param ctx the parse tree
Expand Down
Loading
Loading