Skip to content

Commit f7802ec

Browse files
mumiaoLuckyFBBCythia828liuxy0551HaydenOrz
authored
next merge main (#397)
* feat: improve errorListener msg (#281) * feat: add mysql errorListener and commonErrorListener * feat: improve other sql error msg * feat: support i18n for error msg * feat: add all sql errorMsg unit test * feat: update locale file and change i18n funtion name * test: upate error unit test * 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 <> * fix: spell check (#337) Co-authored-by: liuyi <liuyi@dtstack.com> * ci: check-types and test unit update * feat: collect entity's attribute(#333) * feat(trinosql): collect trino sql's attribute(comment,alias,colType) * feat(hivesql): collect hive sql's attribute(comment,alias,colType) * feat(impalasql): collect attribute(comment, colType, alias) * feat(sparksql): collect entity's attribute (comment,alias, colType) * feat: update endContextList of collect attribute * feat(postgresql): collect hive sql's attribute(alias,colType) * feat: update interface of attrInfo and alter entitycollect ts file * feat(mysql): collect entity's attribute(comment,colType,alias) * ci: fix check-types problem --------- Co-authored-by: zhaoge <> * chore(release): 4.1.0-beta.0 * fix: #362 set hiveVar value (#369) * fix: #371 export EntityContext types (#372) * fix: minimum collect candidates boundary to fix parse performance (#378) * fix: minimum collect candidates boundary to fix parse performance * fix: fix check-types * fix: remove debugger code * fix(flink): fix flinksql syntax error about ROW and function using (#383) Co-authored-by: zhaoge <> * build: pnpm antlr4 --lang all --------- Co-authored-by: 霜序 <976060700@qq.com> Co-authored-by: XCynthia <942884029@qq.com> Co-authored-by: 琉易 <liuxy0551@qq.com> Co-authored-by: liuyi <liuyi@dtstack.com> Co-authored-by: zhaoge <> Co-authored-by: Hayden <hayden9653@gmail.com> Co-authored-by: JackWang032 <64318393+JackWang032@users.noreply.github.com>
1 parent 20f065d commit f7802ec

File tree

93 files changed

+11716
-8618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+11716
-8618
lines changed

CHANGELOG.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [4.1.0-beta.0](https://github.com/DTStack/dt-sql-parser/compare/v4.0.1...v4.1.0-beta.0) (2024-08-27)
6+
7+
8+
### Features
9+
10+
* add alter table stmt ([#312](https://github.com/DTStack/dt-sql-parser/issues/312)) ([5aade9e](https://github.com/DTStack/dt-sql-parser/commit/5aade9e6daafc2c6e70c5202d7ef06572ec37f6e))
11+
* add benchmark test suite ([#273](https://github.com/DTStack/dt-sql-parser/issues/273)) ([de1bd9d](https://github.com/DTStack/dt-sql-parser/commit/de1bd9de4cb7c3b42d51bedd79635eb91afba9ed))
12+
* **basicSql:** remove judge splitListener/collectListener, all sqlParser implements it ([#316](https://github.com/DTStack/dt-sql-parser/issues/316)) ([eb2e920](https://github.com/DTStack/dt-sql-parser/commit/eb2e920e345aef98285ba261c2060db61d1d56b8))
13+
* collect entity's attribute([#333](https://github.com/DTStack/dt-sql-parser/issues/333)) ([a3b6b7e](https://github.com/DTStack/dt-sql-parser/commit/a3b6b7eb8bad2444b16481985278461c35360570))
14+
* **flinksql:** collect comment, type attribute for entity ([#319](https://github.com/DTStack/dt-sql-parser/issues/319)) ([ae52ebd](https://github.com/DTStack/dt-sql-parser/commit/ae52ebdd6b6d1511cf92eb09521b06bdec66ba0d)), closes [#305](https://github.com/DTStack/dt-sql-parser/issues/305)
15+
* improve errorListener msg ([#281](https://github.com/DTStack/dt-sql-parser/issues/281)) ([deef123](https://github.com/DTStack/dt-sql-parser/commit/deef1238bb25d5bfee80ddaf1fea5ad48178d17b))
16+
* sync some useful syntax from antlr/grammars-v4 ([95a1087](https://github.com/DTStack/dt-sql-parser/commit/95a108744bb40e418056faaf86bd97b85dd191f8))
17+
* upgrade trino to 450 ([#323](https://github.com/DTStack/dt-sql-parser/issues/323)) ([2b0de6a](https://github.com/DTStack/dt-sql-parser/commit/2b0de6a3da16561ec52b0c69d4e052226d54a553))
18+
* use common sql to run benchmark ([#326](https://github.com/DTStack/dt-sql-parser/issues/326)) ([76d0900](https://github.com/DTStack/dt-sql-parser/commit/76d090040e7af26227727673a82f77cda08b3f9e))
19+
20+
21+
### Bug Fixes
22+
23+
* alert to alterView ([#346](https://github.com/DTStack/dt-sql-parser/issues/346)) ([9ba5100](https://github.com/DTStack/dt-sql-parser/commit/9ba51007e2f21ab8bc42623596ee281801904cfa))
24+
* **benchmark:** add reports dir judge and remove plsql and include pgsql ([9c534c2](https://github.com/DTStack/dt-sql-parser/commit/9c534c25cacba3cfba6bd234c68e8f27bd90b2e2))
25+
* build mysql ([5d6ff46](https://github.com/DTStack/dt-sql-parser/commit/5d6ff4662a11acf9f16b1f18c41c204922890df9))
26+
* createFunction and createFunctionLoadable ([e83449a](https://github.com/DTStack/dt-sql-parser/commit/e83449a0cc0a50be510c7b4a3337597b1890fc92))
27+
* flinksql function params add more time functions ([#347](https://github.com/DTStack/dt-sql-parser/issues/347)) ([b835c4b](https://github.com/DTStack/dt-sql-parser/commit/b835c4b5b506c8e4bf0bd9c99fe66c15e53a179b))
28+
* **impala:** fix alter table change statement ([#332](https://github.com/DTStack/dt-sql-parser/issues/332)) ([4a9681e](https://github.com/DTStack/dt-sql-parser/commit/4a9681ed3bd188e41c30a6d7be39d6e77df7f61b))
29+
* mysql case when ([#317](https://github.com/DTStack/dt-sql-parser/issues/317)) ([fea1ad1](https://github.com/DTStack/dt-sql-parser/commit/fea1ad1a357b70291a240eca6d2058bab9b49469))
30+
* **postgresql:** combine plsql_unreserved_keyword to unreserved_keyword and remove unused rules ([7884cbe](https://github.com/DTStack/dt-sql-parser/commit/7884cbe37844c057fa41fde4d0716af43c4023af))
31+
* spell check ([#337](https://github.com/DTStack/dt-sql-parser/issues/337)) ([694b0cd](https://github.com/DTStack/dt-sql-parser/commit/694b0cdf15943d02a9402a748155a1b06508af95))
32+
533
### [4.0.2](https://github.com/DTStack/dt-sql-parser/compare/v4.0.1...v4.0.2) (2024-06-19)
634

735

@@ -61,7 +89,7 @@ All notable changes to this project will be documented in this file. See [standa
6189

6290
### Features
6391

64-
* add toMatchUnorderedArrary matcher and apply it ([#271](https://github.com/DTStack/dt-sql-parser/issues/271)) ([a05f099](https://github.com/DTStack/dt-sql-parser/commit/a05f099aa1ad555c408bc2018240fb4611ec09b8))
92+
* add toMatchUnorderedArray matcher and apply it ([#271](https://github.com/DTStack/dt-sql-parser/issues/271)) ([a05f099](https://github.com/DTStack/dt-sql-parser/commit/a05f099aa1ad555c408bc2018240fb4611ec09b8))
6593
* collect entity ([#265](https://github.com/DTStack/dt-sql-parser/issues/265)) ([a997211](https://github.com/DTStack/dt-sql-parser/commit/a99721162be0d463b513f53bb13ada6d10168548)), closes [#256](https://github.com/DTStack/dt-sql-parser/issues/256) [#263](https://github.com/DTStack/dt-sql-parser/issues/263) [#268](https://github.com/DTStack/dt-sql-parser/issues/268)
6694
* migrate to antlr4ng ([#267](https://github.com/DTStack/dt-sql-parser/issues/267)) ([195878d](https://github.com/DTStack/dt-sql-parser/commit/195878da9bb1ff8011b5d60c02389fa66d2bc0b8))
6795
* **spark:** support materialized view for spark sql ([#262](https://github.com/DTStack/dt-sql-parser/issues/262)) ([5ce89cb](https://github.com/DTStack/dt-sql-parser/commit/5ce89cb421de18330d56e23a4ab5b658b2130a0b))

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dt-sql-parser",
3-
"version": "4.0.2",
3+
"version": "4.1.0-beta.0",
44
"authors": "DTStack Corporation",
55
"description": "SQL Parsers for BigData, built with antlr4",
66
"keywords": [

scripts/benchmark.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ function checkVersion() {
4343
if (semver.lt(currentVersion, MIN_VERSION)) {
4444
console.error(
4545
chalk.bold.red(
46-
`Current Node.js version (v${currentVersion}) is lower than required version (v${semver.major(MIN_VERSION)}.x)`
46+
`Current Node.js version (v${currentVersion}) is lower than required version (v${semver.major(
47+
MIN_VERSION
48+
)}.x)`
4749
)
4850
);
4951
return false;
5052
} else {
5153
if (isRelease && semver.lt(currentVersion, RELEASE_VERSION)) {
5254
console.error(
5355
chalk.bold.red(
54-
`Node.js version v${semver.major(RELEASE_VERSION)}.x+ is required for release benchmark!`
56+
`Node.js version v${semver.major(
57+
RELEASE_VERSION
58+
)}.x+ is required for release benchmark!`
5559
)
5660
);
5761
return false;
@@ -81,7 +85,9 @@ function prompt() {
8185
'Cold start' +
8286
(isNodeVersionOk
8387
? ''
84-
: ` (Only supported on Node.js v${semver.major(RECOMMENDED_VERSION)}.x+)`),
88+
: ` (Only supported on Node.js v${semver.major(
89+
RECOMMENDED_VERSION
90+
)}.x+)`),
8591
value: 'cold',
8692
disabled: !isNodeVersionOk,
8793
},

src/grammar/flink/FlinkSqlParser.g4

+23-23
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
@@ -240,17 +241,14 @@ mapTypeDimension
240241

241242
rowTypeDimension
242243
: LESS_SYMBOL columnName columnType (COMMA columnName columnType)* GREATER_SYMBOL
244+
| LR_BRACKET columnName columnType (COMMA columnName columnType)* RR_BRACKET
243245
;
244246

245247
columnConstraint
246248
: (KW_CONSTRAINT constraintName)? KW_PRIMARY KW_KEY (KW_NOT KW_ENFORCED)?
247249
| KW_NOT? KW_NULL
248250
;
249251

250-
commentSpec
251-
: KW_COMMENT STRING_LITERAL
252-
;
253-
254252
metadataColumnDefinition
255253
: columnNameCreate columnType KW_METADATA (KW_FROM metadataKey)? KW_VIRTUAL?
256254
;
@@ -260,7 +258,7 @@ metadataKey
260258
;
261259

262260
computedColumnDefinition
263-
: columnNameCreate KW_AS computedColumnExpression commentSpec?
261+
: columnNameCreate KW_AS computedColumnExpression (KW_COMMENT comment=STRING_LITERAL)?
264262
;
265263

266264
// 计算表达式
@@ -316,11 +314,13 @@ createCatalog
316314
;
317315

318316
createDatabase
319-
: KW_CREATE KW_DATABASE ifNotExists? databasePathCreate commentSpec? withOption
317+
: KW_CREATE KW_DATABASE ifNotExists? databasePathCreate (KW_COMMENT comment=STRING_LITERAL)? withOption
320318
;
321319

322320
createView
323-
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? viewPathCreate columnNameList? commentSpec? KW_AS queryStatement
321+
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? viewPathCreate columnNameList? (
322+
KW_COMMENT comment=STRING_LITERAL
323+
)? KW_AS queryStatement
324324
;
325325

326326
createFunction
@@ -513,8 +513,8 @@ tableReference
513513
;
514514

515515
tablePrimary
516-
: KW_TABLE? tablePath systemTimePeriod? (KW_AS? correlationName)?
517-
| viewPath systemTimePeriod? (KW_AS? correlationName)?
516+
: KW_TABLE? tablePath systemTimePeriod?
517+
| viewPath systemTimePeriod?
518518
| KW_LATERAL KW_TABLE LR_BRACKET functionName LR_BRACKET functionParam (COMMA functionParam)* RR_BRACKET RR_BRACKET
519519
| KW_LATERAL? LR_BRACKET queryStatement RR_BRACKET
520520
| KW_UNNEST LR_BRACKET expression RR_BRACKET
@@ -648,7 +648,7 @@ limitClause
648648
;
649649

650650
partitionByClause
651-
: KW_PARTITION KW_BY columnName (COMMA columnName)*
651+
: KW_PARTITION KW_BY (columnName | primaryExpression) (COMMA (columnName | primaryExpression))*
652652
;
653653

654654
quantifiers
@@ -834,7 +834,7 @@ intervalValue
834834
;
835835

836836
tableAlias
837-
: KW_AS? identifier identifierList?
837+
: KW_AS? alias=identifier identifierList?
838838
;
839839

840840
errorCapturingIdentifier
@@ -1217,4 +1217,4 @@ nonReservedKeywords
12171217
| KW_WEEK
12181218
| KW_YEARS
12191219
| KW_ZONE
1220-
;
1220+
;

src/grammar/hive/HiveSqlParser.g4

+9-5
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ execStatement
8686
| KW_MERGE QUERY_HINT? KW_INTO tableName (KW_AS? id_)? KW_USING joinSourcePart KW_ON expression whenClauses
8787
| KW_PREPARE id_ KW_FROM queryStatementExpression
8888
| KW_EXECUTE id_ KW_USING constantList
89-
| KW_SET configPropertiesItem (DOT configPropertiesItem)* EQUAL .*?
89+
| KW_SET configPropertiesItem ((DOT | COLON) configPropertiesItem)* EQUAL .*?
9090
;
9191

9292
loadStatement
@@ -887,7 +887,9 @@ tableConstraint
887887
;
888888

889889
columnNameTypeConstraint
890-
: colName=columnNameCreate columnType columnConstraint? (KW_COMMENT comment=StringLiteral)?
890+
: colName=columnNameCreate colType=columnType columnConstraint? (
891+
KW_COMMENT comment=StringLiteral
892+
)?
891893
;
892894

893895
columnConstraint
@@ -1363,10 +1365,12 @@ joinToken
13631365
;
13641366

13651367
lateralView
1366-
: KW_LATERAL KW_VIEW KW_OUTER function_ tableAlias (KW_AS id_ (COMMA id_)*)?
1368+
: KW_LATERAL KW_VIEW KW_OUTER function_ alias=tableAlias (KW_AS id_ (COMMA id_)*)?
13671369
| COMMA? KW_LATERAL (
1368-
KW_VIEW function_ tableAlias (KW_AS id_ (COMMA id_)*)?
1369-
| KW_TABLE LPAREN valuesClause RPAREN KW_AS? tableAlias (LPAREN id_ (COMMA id_)* RPAREN)?
1370+
KW_VIEW function_ alias=tableAlias (KW_AS id_ (COMMA id_)*)?
1371+
| KW_TABLE LPAREN valuesClause RPAREN KW_AS? alias=tableAlias (
1372+
LPAREN id_ (COMMA id_)* RPAREN
1373+
)?
13701374
)
13711375
;
13721376

src/grammar/impala/ImpalaSqlParser.g4

+22-18
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/grammar/mysql/MySqlParser.g4

+4-4
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ functionParameter
442442
;
443443

444444
routineOption
445-
: KW_COMMENT STRING_LITERAL # routineComment
445+
: KW_COMMENT comment=STRING_LITERAL # routineComment
446446
| KW_LANGUAGE KW_SQL # routineLanguage
447447
| KW_NOT? KW_DETERMINISTIC # routineBehavior
448448
| (KW_CONTAINS KW_SQL | KW_NO KW_SQL | KW_READS KW_SQL KW_DATA | KW_MODIFIES KW_SQL KW_DATA) # routineData
@@ -483,7 +483,7 @@ constraintSymbol
483483
;
484484

485485
columnDefinition
486-
: dataType columnConstraint*
486+
: colType=dataType columnConstraint*
487487
;
488488

489489
columnConstraint
@@ -494,7 +494,7 @@ columnConstraint
494494
| (KW_AUTO_INCREMENT | KW_ON KW_UPDATE currentTimestamp) # autoIncrementColumnConstraint
495495
| KW_PRIMARY? KW_KEY # primaryKeyColumnConstraint
496496
| KW_UNIQUE KW_KEY? # uniqueKeyColumnConstraint
497-
| KW_COMMENT STRING_LITERAL # commentColumnConstraint
497+
| KW_COMMENT comment=STRING_LITERAL # commentColumnConstraint
498498
| KW_COLUMN_FORMAT colformat=(KW_FIXED | KW_DYNAMIC | KW_DEFAULT) # formatColumnConstraint
499499
| KW_STORAGE storageval=(KW_DISK | KW_MEMORY | KW_DEFAULT) # storageColumnConstraint
500500
| referenceDefinition # referenceColumnConstraint
@@ -536,7 +536,7 @@ tableOption
536536
| KW_DEFAULT? charSet '='? (charsetName | KW_DEFAULT) # tableOptionCharset
537537
| (KW_CHECKSUM | KW_PAGE_CHECKSUM) '='? boolValue=('0' | '1') # tableOptionChecksum
538538
| KW_DEFAULT? KW_COLLATE '='? collationName # tableOptionCollate
539-
| KW_COMMENT '='? STRING_LITERAL # tableOptionComment
539+
| KW_COMMENT '='? comment=STRING_LITERAL # tableOptionComment
540540
| KW_COMPRESSION '='? (STRING_LITERAL | ID) # tableOptionCompression
541541
| KW_CONNECTION '='? STRING_LITERAL # tableOptionConnection
542542
| (KW_DATA | KW_INDEX) KW_DIRECTORY '='? STRING_LITERAL # tableOptionDataDirectory

0 commit comments

Comments
 (0)