Skip to content

Commit 1f1dd19

Browse files
Cythia828liuxy0551
authored andcommitted
feat(flinksql): collect comment, type attribute for entity (#319)
* feat(flinksql): collect comment, type attribute for entity * feat(flinksql): delete console log * fix(#305): delete function ctxToWord,using ctxToText instead of ctxToWord * feat: update attribute's type * feat(flinksql): update flinksql's entitycollect unit test * feat: optimize interface and update unit test * feat: update collect attr detail * feat: optimize interface and some function's arguments * feat: add comment and update params' name * feat: collect alias in select statement * feat: update collect attribute function and update unit test --------- Co-authored-by: zhaoge <>
1 parent ff49c91 commit 1f1dd19

File tree

16 files changed

+3277
-2982
lines changed

16 files changed

+3277
-2982
lines changed

src/grammar/flink/FlinkSqlParser.g4

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ createTable
156156
simpleCreateTable
157157
: KW_CREATE KW_TEMPORARY? KW_TABLE ifNotExists? tablePathCreate LR_BRACKET columnOptionDefinition (
158158
COMMA columnOptionDefinition
159-
)* (COMMA watermarkDefinition)? (COMMA tableConstraint)? (COMMA selfDefinitionClause)? RR_BRACKET commentSpec? partitionDefinition? withOption
160-
likeDefinition?
159+
)* (COMMA watermarkDefinition)? (COMMA tableConstraint)? (COMMA selfDefinitionClause)? RR_BRACKET (
160+
KW_COMMENT comment=STRING_LITERAL
161+
)? partitionDefinition? withOption likeDefinition?
161162
;
162163

163164
/*
@@ -175,7 +176,7 @@ columnOptionDefinition
175176
;
176177

177178
physicalColumnDefinition
178-
: columnNameCreate columnType columnConstraint? commentSpec?
179+
: columnNameCreate columnType columnConstraint? (KW_COMMENT comment=STRING_LITERAL)?
179180
;
180181

181182
columnNameCreate
@@ -193,8 +194,8 @@ columnNameList
193194
;
194195

195196
columnType
196-
: typeName=(KW_DATE | KW_BOOLEAN | KW_NULL)
197-
| typeName=(
197+
: colType=(KW_DATE | KW_BOOLEAN | KW_NULL)
198+
| colType=(
198199
KW_CHAR
199200
| KW_VARCHAR
200201
| KW_STRING
@@ -210,12 +211,12 @@ columnType
210211
| KW_TIMESTAMP_LTZ
211212
| KW_DATETIME
212213
) lengthOneDimension?
213-
| typeName=KW_TIMESTAMP lengthOneDimension? ((KW_WITHOUT | KW_WITH) KW_LOCAL? KW_TIME KW_ZONE)?
214-
| typeName=(KW_DECIMAL | KW_DEC | KW_NUMERIC | KW_FLOAT | KW_DOUBLE) lengthTwoOptionalDimension?
215-
| type=(KW_ARRAY | KW_MULTISET) lengthOneTypeDimension?
216-
| type=KW_MAP mapTypeDimension?
217-
| type=KW_ROW rowTypeDimension?
218-
| type=KW_RAW lengthTwoStringDimension?
214+
| colType=KW_TIMESTAMP lengthOneDimension? ((KW_WITHOUT | KW_WITH) KW_LOCAL? KW_TIME KW_ZONE)?
215+
| colType=(KW_DECIMAL | KW_DEC | KW_NUMERIC | KW_FLOAT | KW_DOUBLE) lengthTwoOptionalDimension?
216+
| colType=(KW_ARRAY | KW_MULTISET) lengthOneTypeDimension?
217+
| colType=KW_MAP mapTypeDimension?
218+
| colType=KW_ROW rowTypeDimension?
219+
| colType=KW_RAW lengthTwoStringDimension?
219220
;
220221

221222
lengthOneDimension
@@ -247,10 +248,6 @@ columnConstraint
247248
| KW_NOT? KW_NULL
248249
;
249250

250-
commentSpec
251-
: KW_COMMENT STRING_LITERAL
252-
;
253-
254251
metadataColumnDefinition
255252
: columnNameCreate columnType KW_METADATA (KW_FROM metadataKey)? KW_VIRTUAL?
256253
;
@@ -260,7 +257,7 @@ metadataKey
260257
;
261258

262259
computedColumnDefinition
263-
: columnNameCreate KW_AS computedColumnExpression commentSpec?
260+
: columnNameCreate KW_AS computedColumnExpression (KW_COMMENT comment=STRING_LITERAL)?
264261
;
265262

266263
// 计算表达式
@@ -316,11 +313,13 @@ createCatalog
316313
;
317314

318315
createDatabase
319-
: KW_CREATE KW_DATABASE ifNotExists? databasePathCreate commentSpec? withOption
316+
: KW_CREATE KW_DATABASE ifNotExists? databasePathCreate (KW_COMMENT comment=STRING_LITERAL)? withOption
320317
;
321318

322319
createView
323-
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? viewPathCreate columnNameList? commentSpec? KW_AS queryStatement
320+
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? viewPathCreate columnNameList? (
321+
KW_COMMENT comment=STRING_LITERAL
322+
)? KW_AS queryStatement
324323
;
325324

326325
createFunction
@@ -513,8 +512,8 @@ tableReference
513512
;
514513

515514
tablePrimary
516-
: KW_TABLE? tablePath systemTimePeriod? (KW_AS? correlationName)?
517-
| viewPath systemTimePeriod? (KW_AS? correlationName)?
515+
: KW_TABLE? tablePath systemTimePeriod?
516+
| viewPath systemTimePeriod?
518517
| KW_LATERAL KW_TABLE LR_BRACKET functionName LR_BRACKET functionParam (COMMA functionParam)* RR_BRACKET RR_BRACKET
519518
| KW_LATERAL? LR_BRACKET queryStatement RR_BRACKET
520519
| KW_UNNEST LR_BRACKET expression RR_BRACKET
@@ -834,7 +833,7 @@ intervalValue
834833
;
835834

836835
tableAlias
837-
: KW_AS? identifier identifierList?
836+
: KW_AS? alias=identifier identifierList?
838837
;
839838

840839
errorCapturingIdentifier

src/lib/flink/FlinkSqlParser.interp

Lines changed: 2 additions & 3 deletions
Large diffs are not rendered by default.

src/lib/flink/FlinkSqlParser.ts

Lines changed: 2353 additions & 2435 deletions
Large diffs are not rendered by default.

src/lib/flink/FlinkSqlParserListener.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import { LengthOneTypeDimensionContext } from "./FlinkSqlParser.js";
4444
import { MapTypeDimensionContext } from "./FlinkSqlParser.js";
4545
import { RowTypeDimensionContext } from "./FlinkSqlParser.js";
4646
import { ColumnConstraintContext } from "./FlinkSqlParser.js";
47-
import { CommentSpecContext } from "./FlinkSqlParser.js";
4847
import { MetadataColumnDefinitionContext } from "./FlinkSqlParser.js";
4948
import { MetadataKeyContext } from "./FlinkSqlParser.js";
5049
import { ComputedColumnDefinitionContext } from "./FlinkSqlParser.js";
@@ -73,7 +72,7 @@ import { AddConstraintContext } from "./FlinkSqlParser.js";
7372
import { DropConstraintContext } from "./FlinkSqlParser.js";
7473
import { AddUniqueContext } from "./FlinkSqlParser.js";
7574
import { NotForcedContext } from "./FlinkSqlParser.js";
76-
import { AlertViewContext } from "./FlinkSqlParser.js";
75+
import { AlterViewContext } from "./FlinkSqlParser.js";
7776
import { AlterDatabaseContext } from "./FlinkSqlParser.js";
7877
import { AlterFunctionContext } from "./FlinkSqlParser.js";
7978
import { DropCatalogContext } from "./FlinkSqlParser.js";
@@ -588,16 +587,6 @@ export class FlinkSqlParserListener implements ParseTreeListener {
588587
* @param ctx the parse tree
589588
*/
590589
exitColumnConstraint?: (ctx: ColumnConstraintContext) => void;
591-
/**
592-
* Enter a parse tree produced by `FlinkSqlParser.commentSpec`.
593-
* @param ctx the parse tree
594-
*/
595-
enterCommentSpec?: (ctx: CommentSpecContext) => void;
596-
/**
597-
* Exit a parse tree produced by `FlinkSqlParser.commentSpec`.
598-
* @param ctx the parse tree
599-
*/
600-
exitCommentSpec?: (ctx: CommentSpecContext) => void;
601590
/**
602591
* Enter a parse tree produced by `FlinkSqlParser.metadataColumnDefinition`.
603592
* @param ctx the parse tree
@@ -883,15 +872,15 @@ export class FlinkSqlParserListener implements ParseTreeListener {
883872
*/
884873
exitNotForced?: (ctx: NotForcedContext) => void;
885874
/**
886-
* Enter a parse tree produced by `FlinkSqlParser.alertView`.
875+
* Enter a parse tree produced by `FlinkSqlParser.alterView`.
887876
* @param ctx the parse tree
888877
*/
889-
enterAlertView?: (ctx: AlertViewContext) => void;
878+
enterAlterView?: (ctx: AlterViewContext) => void;
890879
/**
891-
* Exit a parse tree produced by `FlinkSqlParser.alertView`.
880+
* Exit a parse tree produced by `FlinkSqlParser.alterView`.
892881
* @param ctx the parse tree
893882
*/
894-
exitAlertView?: (ctx: AlertViewContext) => void;
883+
exitAlterView?: (ctx: AlterViewContext) => void;
895884
/**
896885
* Enter a parse tree produced by `FlinkSqlParser.alterDatabase`.
897886
* @param ctx the parse tree

src/lib/flink/FlinkSqlParserVisitor.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import { LengthOneTypeDimensionContext } from "./FlinkSqlParser.js";
4444
import { MapTypeDimensionContext } from "./FlinkSqlParser.js";
4545
import { RowTypeDimensionContext } from "./FlinkSqlParser.js";
4646
import { ColumnConstraintContext } from "./FlinkSqlParser.js";
47-
import { CommentSpecContext } from "./FlinkSqlParser.js";
4847
import { MetadataColumnDefinitionContext } from "./FlinkSqlParser.js";
4948
import { MetadataKeyContext } from "./FlinkSqlParser.js";
5049
import { ComputedColumnDefinitionContext } from "./FlinkSqlParser.js";
@@ -73,7 +72,7 @@ import { AddConstraintContext } from "./FlinkSqlParser.js";
7372
import { DropConstraintContext } from "./FlinkSqlParser.js";
7473
import { AddUniqueContext } from "./FlinkSqlParser.js";
7574
import { NotForcedContext } from "./FlinkSqlParser.js";
76-
import { AlertViewContext } from "./FlinkSqlParser.js";
75+
import { AlterViewContext } from "./FlinkSqlParser.js";
7776
import { AlterDatabaseContext } from "./FlinkSqlParser.js";
7877
import { AlterFunctionContext } from "./FlinkSqlParser.js";
7978
import { DropCatalogContext } from "./FlinkSqlParser.js";
@@ -447,12 +446,6 @@ export class FlinkSqlParserVisitor<Result> extends AbstractParseTreeVisitor<Resu
447446
* @return the visitor result
448447
*/
449448
visitColumnConstraint?: (ctx: ColumnConstraintContext) => Result;
450-
/**
451-
* Visit a parse tree produced by `FlinkSqlParser.commentSpec`.
452-
* @param ctx the parse tree
453-
* @return the visitor result
454-
*/
455-
visitCommentSpec?: (ctx: CommentSpecContext) => Result;
456449
/**
457450
* Visit a parse tree produced by `FlinkSqlParser.metadataColumnDefinition`.
458451
* @param ctx the parse tree
@@ -624,11 +617,11 @@ export class FlinkSqlParserVisitor<Result> extends AbstractParseTreeVisitor<Resu
624617
*/
625618
visitNotForced?: (ctx: NotForcedContext) => Result;
626619
/**
627-
* Visit a parse tree produced by `FlinkSqlParser.alertView`.
620+
* Visit a parse tree produced by `FlinkSqlParser.alterView`.
628621
* @param ctx the parse tree
629622
* @return the visitor result
630623
*/
631-
visitAlertView?: (ctx: AlertViewContext) => Result;
624+
visitAlterView?: (ctx: AlterViewContext) => Result;
632625
/**
633626
* Visit a parse tree produced by `FlinkSqlParser.alterDatabase`.
634627
* @param ctx the parse tree

0 commit comments

Comments
 (0)