Skip to content

Commit ebc5ed0

Browse files
author
zhaoge
committed
feat(impalasql): collect attribute(comment, colType, alias)
1 parent ab2484c commit ebc5ed0

File tree

9 files changed

+3642
-3356
lines changed

9 files changed

+3642
-3356
lines changed

src/grammar/impala/ImpalaSqlParser.g4

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,20 @@ createKuduTableAsSelect
9696
: KW_CREATE KW_EXTERNAL? KW_TABLE ifNotExists? tableNameCreate (
9797
LPAREN kuduTableElement (COMMA kuduTableElement)* (COMMA KW_PRIMARY KW_KEY columnAliases)? RPAREN
9898
)? (KW_PRIMARY KW_KEY columnAliases?)? (KW_PARTITION KW_BY kuduPartitionClause)? (
99-
KW_COMMENT stringLiteral
99+
commentClause
100100
)? KW_STORED KW_AS KW_KUDU (KW_TBLPROPERTIES tblProp=properties)? (KW_AS queryStatement)?
101101
;
102102

103103
createView
104-
: KW_CREATE KW_VIEW ifNotExists? viewNameCreate viewColumns? (KW_COMMENT stringLiteral)? (
104+
: KW_CREATE KW_VIEW ifNotExists? viewNameCreate viewColumns? commentClause? (
105105
KW_TBLPROPERTIES tblProp=properties
106106
)? KW_AS queryStatement
107107
;
108108

109109
createSchema
110-
: KW_CREATE (KW_SCHEMA | KW_DATABASE) ifNotExists? databaseNameCreate (
111-
KW_COMMENT comment=stringLiteral
112-
)? (KW_LOCATION location=stringLiteral)?
110+
: KW_CREATE (KW_SCHEMA | KW_DATABASE) ifNotExists? databaseNameCreate (commentClause)? (
111+
KW_LOCATION location=stringLiteral
112+
)?
113113
;
114114

115115
createRole
@@ -119,14 +119,14 @@ createRole
119119
createAggregateFunction
120120
: KW_CREATE KW_AGGREGATE? KW_FUNCTION ifNotExists? functionNameCreate (
121121
LPAREN (type (COMMA type)*)? RPAREN
122-
)? KW_RETURNS type (KW_INTERMEDIATE type)? KW_LOCATION STRING (KW_INIT_FN EQ STRING)? KW_UPDATE_FN EQ STRING KW_MERGE_FN EQ STRING (
122+
)? KW_RETURNS returnType=type (KW_INTERMEDIATE type)? KW_LOCATION STRING (KW_INIT_FN EQ STRING)? KW_UPDATE_FN EQ STRING KW_MERGE_FN EQ STRING (
123123
KW_PREPARE_FN EQ STRING
124124
)? (KW_CLOSEFN EQ STRING)? (KW_SERIALIZE_FN EQ STRING)? (KW_FINALIZE_FN EQ STRING)?
125125
;
126126

127127
createFunction
128128
: KW_CREATE KW_FUNCTION ifNotExists? functionNameCreate (LPAREN (type (COMMA type)*)? RPAREN)? (
129-
KW_RETURNS type
129+
KW_RETURNS returnType=type
130130
)? KW_LOCATION STRING KW_SYMBOL EQ symbol=stringLiteral
131131
;
132132

@@ -569,11 +569,9 @@ tableOrViewPath
569569
;
570570

571571
createCommonItem
572-
: (KW_SORT KW_BY columnAliases)? (KW_COMMENT comment=stringLiteral)? (
573-
KW_ROW KW_FORMAT rowFormat
574-
)? (KW_WITH KW_SERDEPROPERTIES serdProp=properties)? (KW_STORED KW_AS fileFormat)? (
575-
KW_LOCATION location=stringLiteral
576-
)? (
572+
: (KW_SORT KW_BY columnAliases)? commentClause? (KW_ROW KW_FORMAT rowFormat)? (
573+
KW_WITH KW_SERDEPROPERTIES serdProp=properties
574+
)? (KW_STORED KW_AS fileFormat)? (KW_LOCATION location=stringLiteral)? (
577575
KW_CACHED KW_IN cacheName=qualifiedName (KW_WITH KW_REPLICATION EQ INTEGER_VALUE)?
578576
| KW_UNCACHED
579577
)? (KW_TBLPROPERTIES tblProp=properties)?
@@ -588,9 +586,11 @@ assignmentItem
588586
;
589587

590588
viewColumns
591-
: LPAREN columnNamePathCreate (KW_COMMENT stringLiteral)? (
592-
COMMA columnNamePathCreate (KW_COMMENT stringLiteral)?
593-
)* RPAREN
589+
: LPAREN viewColumnItem? (COMMA viewColumnItem?)* RPAREN
590+
;
591+
592+
viewColumnItem
593+
: columnNamePathCreate commentClause?
594594
;
595595

596596
queryStatement
@@ -621,19 +621,23 @@ columnSpec
621621
;
622622

623623
columnDefinition
624-
: columnNamePathCreate type (KW_COMMENT stringLiteral)?
624+
: columnNamePathCreate colType=type commentClause?
625625
;
626626

627627
kuduTableElement
628628
: kuduColumnDefinition
629629
;
630630

631631
kuduColumnDefinition
632-
: columnNamePathCreate type (kuduAttributes kuduAttributes*?)? (KW_COMMENT stringLiteral)? (
632+
: columnNamePathCreate colType=type (kuduAttributes kuduAttributes*?)? commentClause? (
633633
KW_PRIMARY KW_KEY
634634
)?
635635
;
636636

637+
commentClause
638+
: KW_COMMENT comment=stringLiteral
639+
;
640+
637641
columnSpecWithKudu
638642
: columnSpec (kuduAttributes kuduAttributes*?)?
639643
;
@@ -838,7 +842,7 @@ sampleType
838842
;
839843

840844
aliasedRelation
841-
: relationPrimary (KW_AS? identifier columnAliases?)?
845+
: relationPrimary (KW_AS? alias=identifier columnAliases?)?
842846
;
843847

844848
columnAliases

src/lib/impala/ImpalaSqlParser.interp

Lines changed: 3 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)