Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dt-sql-parser",
"version": "4.5.0-beta.0",
"version": "4.5.0-beta.1",
"authors": "DTStack Corporation",
"description": "SQL Parsers for BigData, built with antlr4",
"keywords": [
Expand Down
23 changes: 19 additions & 4 deletions src/grammar/flink/FlinkSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,24 @@ columnNameCreate
| expression
;

emptyColumn
:
;

columnName
: uid
| {this.shouldMatchEmpty()}?
: uidAllowEmpty
| {this.shouldMatchEmpty()}? emptyColumn
;

columnNamePath
: uid
;

columnNamePathAllowEmpty
: uidAllowEmpty
| {this.shouldMatchEmpty()}? emptyColumn
;

columnNameList
: LR_BRACKET columnName (COMMA columnName)* RR_BRACKET
;
Expand Down Expand Up @@ -500,6 +509,7 @@ columnProjectItem
| selectLiteralColumnName (columnAlias | KW_AS? expression)?
| tableAllColumns columnAlias?
| selectExpressionColumnName (columnAlias | KW_AS? columnName)?
| {this.shouldMatchEmpty()}? emptyColumn
;

selectWindowItemColumnName
Expand Down Expand Up @@ -614,12 +624,12 @@ columnDescriptor
;

joinCondition
: KW_ON booleanExpression
: KW_ON (booleanExpression | columnNamePathAllowEmpty (EQUAL_SYMBOL columnNamePathAllowEmpty)?)
| KW_USING columnNameList
;

whereClause
: KW_WHERE booleanExpression
: KW_WHERE (booleanExpression | columnNamePathAllowEmpty)
;

groupByClause
Expand Down Expand Up @@ -1037,6 +1047,11 @@ uid
: identifier (DOT identifier)*
;

uidAllowEmpty
: identifier (DOT identifier)*
| {this.shouldMatchEmpty()}? identifier DOT emptyColumn
;

withOption
: KW_WITH tablePropertyList
;
Expand Down
28 changes: 23 additions & 5 deletions src/grammar/hive/HiveSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -754,14 +754,19 @@ columnNameList
;

columnName
: poolPath
| {this.shouldMatchEmpty()}?
: poolPathAllowEmpty
| {this.shouldMatchEmpty()}? emptyColumn
;

columnNamePath
: poolPath
;

columnNamePathAllowEmpty
: poolPathAllowEmpty
| {this.shouldMatchEmpty()}? emptyColumn
;

columnNameCreate
: id_
;
Expand Down Expand Up @@ -1346,7 +1351,10 @@ atomjoinSource

joinSource
: atomjoinSource (
joinToken joinSourcePart (KW_ON expression | KW_USING columnParenthesesList)?
joinToken joinSourcePart (
KW_ON (expression | columnNamePathAllowEmpty (EQUAL columnNamePathAllowEmpty)?)
| KW_USING columnParenthesesList
)?
)*
;

Expand Down Expand Up @@ -1469,7 +1477,7 @@ Rules for parsing whereClause
where a=b and ...
*/
whereClause
: KW_WHERE expression
: KW_WHERE (expression | columnNamePathAllowEmpty)
;

/**
Expand Down Expand Up @@ -1528,6 +1536,7 @@ selectItem
| KW_AS LPAREN alias=id_ (COMMA alias=id_)* RPAREN
)?
)
| {this.shouldMatchEmpty()}? emptyColumn
;

selectLiteralColumnName
Expand Down Expand Up @@ -1600,7 +1609,7 @@ groupingSetExpression
;

havingClause
: KW_HAVING expression
: KW_HAVING (expression | columnNamePathAllowEmpty)
;

qualifyClause
Expand Down Expand Up @@ -2425,10 +2434,19 @@ decimal
| KW_NUMERIC
;

emptyColumn
:
;

poolPath
: id_ (DOT id_)*
;

poolPathAllowEmpty
: id_ (DOT id_)*
| {this.shouldMatchEmpty()}? id_ (DOT emptyColumn)*
;

triggerAtomExpression
: id_ GREATERTHAN (Number | StringLiteral)
;
Expand Down
25 changes: 20 additions & 5 deletions src/grammar/impala/ImpalaSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,24 @@ functionNamePath
| qualifiedName
;

emptyColumn
:
;

columnNamePath
: qualifiedName
| {this.shouldMatchEmpty()}?
: {this.shouldMatchEmpty()}? emptyColumn
| qualifiedNameAllowEmpty
;

columnName
: qualifiedName
;

columnNameAllowEmpty
: {this.shouldMatchEmpty()}? emptyColumn
| qualifiedNameAllowEmpty
;

tableOrViewPath
: tableNamePath
| viewNamePath
Expand Down Expand Up @@ -781,11 +790,11 @@ selectList
;

whereClause
: KW_WHERE where=booleanExpression
: KW_WHERE (where=booleanExpression | columnNameAllowEmpty)
;

havingClause
: KW_HAVING having=booleanExpression
: KW_HAVING (having=booleanExpression | columnNameAllowEmpty)
;

groupBy
Expand Down Expand Up @@ -814,6 +823,7 @@ selectItem
: selectLiteralColumnName columnAlias?
| selectExpressionColumnName columnAlias?
| tableAllColumns
| {this.shouldMatchEmpty()}? emptyColumn
;

columnAlias
Expand Down Expand Up @@ -854,7 +864,7 @@ joinType
;

joinCriteria
: KW_ON booleanExpression
: KW_ON (booleanExpression | columnNameAllowEmpty)
| KW_USING LPAREN identifier (COMMA identifier)* RPAREN
;

Expand Down Expand Up @@ -1149,6 +1159,11 @@ qualifiedName
: identifier (DOT identifier)*
;

qualifiedNameAllowEmpty
: {this.shouldMatchEmpty()}? (identifier DOT emptyColumn | emptyColumn)
| identifier (DOT identifier)*
;

principal
: KW_ROLE identifier # rolePrincipal
| KW_USER identifier # userPrincipal
Expand Down
29 changes: 22 additions & 7 deletions src/grammar/mysql/MySqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ joinPart
;

joinSpec
: (KW_ON expression)
: (KW_ON (expression | columnNamePathAllowEmpty))
| KW_USING '(' columnNames ')'
;

Expand Down Expand Up @@ -1205,9 +1205,10 @@ selectElements
;

selectElement
: tableAllColumns
| selectLiteralColumnName (KW_AS? alias=uid)?
| selectExpressionColumnName (KW_AS? alias=uid)?
: tableAllColumns # selectElement_star
| selectLiteralColumnName (KW_AS? alias=uid)? # selectElement_label
| selectExpressionColumnName (KW_AS? alias=uid)? # selectElement_expr
| uid DOT {this.shouldMatchEmpty()}? emptyColumn # selectElement_dot_empty
;

tableAllColumns
Expand Down Expand Up @@ -1249,7 +1250,7 @@ selectLinesInto
;

fromClause
: (KW_FROM tableSources)? (KW_WHERE whereExpr=expression)?
: (KW_FROM tableSources)? (KW_WHERE (whereExpr=expression | columnNamePathAllowEmpty))?
;

groupByClause
Expand Down Expand Up @@ -2419,10 +2420,24 @@ columnNames
: columnName (',' columnName)*
;

emptyColumn
:
;

columnName
: uid (dottedId dottedId?)?
| .? dottedId dottedId?
| {this.shouldMatchEmpty()}?
| {this.shouldMatchEmpty()}? emptyColumn
;

columnNamePath
: uid (dottedId dottedId?)?
| .? dottedId dottedId?
;

columnNamePathAllowEmpty
: {this.shouldMatchEmpty()}? emptyColumn
| uid (dottedId dottedId?)?
;

tableSpaceNameCreate
Expand Down Expand Up @@ -2998,7 +3013,7 @@ expressionAtom
| left=expressionAtom jsonOperator right=expressionAtom # jsonExpressionAtom
| left=expressionAtom bitOperator right=expressionAtom # bitExpressionAtom
| left=expressionAtom mathOperator right=expressionAtom # mathExpressionAtom
| columnName # columnNameExpressionAtom
| columnNamePath # columnNameExpressionAtom
;

unaryOperator
Expand Down
17 changes: 15 additions & 2 deletions src/grammar/postgresql/PostgreSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -2615,7 +2615,8 @@ when_clause
;

indirectionEl
: DOT (colLabel | STAR)
: DOT indirectionLabel
| DOT STAR
| OPEN_BRACKET (expression | expression? COLON expression?) CLOSE_BRACKET
;

Expand All @@ -2634,6 +2635,8 @@ targetList
targetEl
: tableAllColumns # target_star
| (selectLiteralColumnName | selectExpressionColumnName) (KW_AS? alias=identifier |) # target_label
| colId DOT {this.entityCollecting}? emptyColumn # target_dot_empty
| {this.entityCollecting}? emptyColumn # target_empty
;

tableAllColumns
Expand Down Expand Up @@ -2722,9 +2725,13 @@ procedureNameCreate
| colId indirection
;

// Empty column rule for entity collection
emptyColumn
:
;

columnName
: colId optIndirection
| {this.shouldMatchEmpty()}?
;

columnNamePath
Expand Down Expand Up @@ -2795,6 +2802,12 @@ colLabel
| reservedKeyword
;

indirectionLabel
: identifier
| colNameKeyword
| typeFuncNameKeyword
;

identifier
: Identifier (KW_UESCAPE anysconst)?
| stringConst
Expand Down
21 changes: 18 additions & 3 deletions src/grammar/spark/SparkSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,24 @@ viewName
: viewIdentifier
;

emptyColumn
:
;

columnName
: multipartIdentifier
| {this.shouldMatchEmpty()}?
: multipartIdentifierAllowEmpty
| {this.shouldMatchEmpty()}? emptyColumn
;

columnNamePath
: multipartIdentifier
;

columnNamePathAllowEmpty
: multipartIdentifierAllowEmpty
| {this.shouldMatchEmpty()}? emptyColumn
;

columnNameSeq
: columnName (COMMA columnName)*
;
Expand Down Expand Up @@ -680,7 +689,7 @@ joinType
;

joinCriteria
: KW_ON booleanExpression
: KW_ON (booleanExpression | columnNamePathAllowEmpty (EQ columnNamePathAllowEmpty)?)
| KW_USING identifierList
;

Expand Down Expand Up @@ -804,6 +813,11 @@ multipartIdentifier
: parts+=errorCapturingIdentifier (DOT parts+=errorCapturingIdentifier)*
;

multipartIdentifierAllowEmpty
: multipartIdentifier
| {this.shouldMatchEmpty()}? multipartIdentifier DOT emptyColumn
;

multipartIdentifierPropertyList
: multipartIdentifierProperty (COMMA multipartIdentifierProperty)*
;
Expand Down Expand Up @@ -836,6 +850,7 @@ namedExpression
: (tableAllColumns | selectLiteralColumnName | selectExpressionColumnName) (
KW_AS? (alias=errorCapturingIdentifier | identifierList)
)?
| {this.shouldMatchEmpty()}? emptyColumn
;

namedExpressionSeq
Expand Down
Loading
Loading