Skip to content

Commit

Permalink
feat(flinksql): collect comment, type attribute for entity (DTStack#319)
Browse files Browse the repository at this point in the history
* feat(flinksql): collect comment, type attribute for entity

* feat(flinksql): delete console log

* fix(DTStack#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 <>
  • Loading branch information
Cythia828 authored and HaydenOrz committed Aug 27, 2024
1 parent deef123 commit ae52ebd
Show file tree
Hide file tree
Showing 16 changed files with 3,277 additions and 2,982 deletions.
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
: 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
5 changes: 2 additions & 3 deletions src/lib/flink/FlinkSqlParser.interp

Large diffs are not rendered by default.

4,788 changes: 2,353 additions & 2,435 deletions src/lib/flink/FlinkSqlParser.ts

Large diffs are not rendered by default.

21 changes: 5 additions & 16 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 @@ -73,7 +72,7 @@ import { AddConstraintContext } from "./FlinkSqlParser.js";
import { DropConstraintContext } from "./FlinkSqlParser.js";
import { AddUniqueContext } from "./FlinkSqlParser.js";
import { NotForcedContext } from "./FlinkSqlParser.js";
import { AlertViewContext } from "./FlinkSqlParser.js";
import { AlterViewContext } from "./FlinkSqlParser.js";
import { AlterDatabaseContext } from "./FlinkSqlParser.js";
import { AlterFunctionContext } from "./FlinkSqlParser.js";
import { DropCatalogContext } 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 Expand Up @@ -883,15 +872,15 @@ export class FlinkSqlParserListener implements ParseTreeListener {
*/
exitNotForced?: (ctx: NotForcedContext) => void;
/**
* Enter a parse tree produced by `FlinkSqlParser.alertView`.
* Enter a parse tree produced by `FlinkSqlParser.alterView`.
* @param ctx the parse tree
*/
enterAlertView?: (ctx: AlertViewContext) => void;
enterAlterView?: (ctx: AlterViewContext) => void;
/**
* Exit a parse tree produced by `FlinkSqlParser.alertView`.
* Exit a parse tree produced by `FlinkSqlParser.alterView`.
* @param ctx the parse tree
*/
exitAlertView?: (ctx: AlertViewContext) => void;
exitAlterView?: (ctx: AlterViewContext) => void;
/**
* Enter a parse tree produced by `FlinkSqlParser.alterDatabase`.
* @param ctx the parse tree
Expand Down
13 changes: 3 additions & 10 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 @@ -73,7 +72,7 @@ import { AddConstraintContext } from "./FlinkSqlParser.js";
import { DropConstraintContext } from "./FlinkSqlParser.js";
import { AddUniqueContext } from "./FlinkSqlParser.js";
import { NotForcedContext } from "./FlinkSqlParser.js";
import { AlertViewContext } from "./FlinkSqlParser.js";
import { AlterViewContext } from "./FlinkSqlParser.js";
import { AlterDatabaseContext } from "./FlinkSqlParser.js";
import { AlterFunctionContext } from "./FlinkSqlParser.js";
import { DropCatalogContext } 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 Expand Up @@ -624,11 +617,11 @@ export class FlinkSqlParserVisitor<Result> extends AbstractParseTreeVisitor<Resu
*/
visitNotForced?: (ctx: NotForcedContext) => Result;
/**
* Visit a parse tree produced by `FlinkSqlParser.alertView`.
* Visit a parse tree produced by `FlinkSqlParser.alterView`.
* @param ctx the parse tree
* @return the visitor result
*/
visitAlertView?: (ctx: AlertViewContext) => Result;
visitAlterView?: (ctx: AlterViewContext) => Result;
/**
* Visit a parse tree produced by `FlinkSqlParser.alterDatabase`.
* @param ctx the parse tree
Expand Down
Loading

0 comments on commit ae52ebd

Please sign in to comment.