Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(all sql): add all sql expression column #358

Open
wants to merge 7 commits into
base: next
Choose a base branch
from
Open
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
20 changes: 12 additions & 8 deletions src/grammar/flink/FlinkSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ columnName
| {this.shouldMatchEmpty()}?
;

columnNamePath
: uid
;

columnNameList
: LR_BRACKET columnName (COMMA columnName)* RR_BRACKET
;
Expand Down Expand Up @@ -451,9 +455,9 @@ queryStatement
: valuesCaluse
| withClause queryStatement
| LR_BRACKET queryStatement RR_BRACKET
| left=queryStatement operator=(KW_INTERSECT | KW_UNION | KW_EXCEPT) KW_ALL? right=queryStatement orderByCaluse? limitClause?
| selectClause orderByCaluse? limitClause?
| selectStatement orderByCaluse? limitClause?
| left=queryStatement operator=(KW_INTERSECT | KW_UNION | KW_EXCEPT) KW_ALL? right=queryStatement orderByClause? limitClause?
| selectClause orderByClause? limitClause?
| selectStatement orderByClause? limitClause?
;

valuesCaluse
Expand Down Expand Up @@ -626,15 +630,15 @@ namedWindow
;

windowSpec
: name=errorCapturingIdentifier? LR_BRACKET partitionByClause? orderByCaluse? windowFrame? RR_BRACKET
: name=errorCapturingIdentifier? LR_BRACKET partitionByClause? orderByClause? windowFrame? RR_BRACKET
;

matchRecognizeClause
: KW_MATCH_RECOGNIZE LR_BRACKET partitionByClause? orderByCaluse? measuresClause? outputMode? afterMatchStrategy? patternDefination?
: KW_MATCH_RECOGNIZE LR_BRACKET partitionByClause? orderByClause? measuresClause? outputMode? afterMatchStrategy? patternDefination?
patternVariablesDefination RR_BRACKET (KW_AS? identifier)?
;

orderByCaluse
orderByClause
: KW_ORDER KW_BY orderItemDefition (COMMA orderItemDefition)*
;

Expand Down Expand Up @@ -763,7 +767,7 @@ primaryExpression
// | identifier '->' expression #lambda
// | '(' identifier (',' identifier)+ ')' '->' expression #lambda
| value=primaryExpression LS_BRACKET index=valueExpression RS_BRACKET # subscript
| identifier # columnReference
| columnNamePath # columnReference
| dereferenceDefinition # dereference
| LR_BRACKET expression RR_BRACKET # parenthesizedExpression
| KW_CURRENT_TIMESTAMP # dateFunctionExpression
Expand Down Expand Up @@ -1216,4 +1220,4 @@ nonReservedKeywords
| KW_WEEK
| KW_YEARS
| KW_ZONE
;
;
12 changes: 10 additions & 2 deletions src/grammar/hive/HiveSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ columnName
| {this.shouldMatchEmpty()}?
;

columnNamePath
: poolPath
;

columnNameCreate
: id_
;
Expand Down Expand Up @@ -1437,7 +1441,7 @@ subQuerySource
Rules for parsing PTF clauses
*/
partitioningSpec
: KW_PARTITION KW_BY expressions orderByClause?
: partitionByClause orderByClause?
| orderByClause
| distributeByClause sortByClause?
| sortByClause
Expand Down Expand Up @@ -1613,6 +1617,10 @@ orderByClause
: KW_ORDER KW_BY columnRefOrder (COMMA columnRefOrder)*
;

partitionByClause
: KW_PARTITION KW_BY expressions
;

clusterByClause
: KW_CLUSTER KW_BY expressions
;
Expand Down Expand Up @@ -1714,7 +1722,7 @@ constant
| KW_FALSE
| KW_NULL
| p=QUESTION
| Identifier
| columnNamePath
;

intervalValue
Expand Down
34 changes: 24 additions & 10 deletions src/grammar/impala/ImpalaSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,18 @@ deleteStatement
;

delete
: KW_DELETE KW_FROM? tableNamePath (KW_WHERE booleanExpression)?
: KW_DELETE KW_FROM? tableNamePath (whereClause)?
;

deleteTableRef
: KW_DELETE tableNamePath (KW_AS? identifier)? KW_FROM (relation (COMMA relation)*)? (
KW_WHERE booleanExpression
whereClause
)?
;

updateStatement
: KW_UPDATE tableNamePath KW_SET assignmentList (KW_FROM relation (COMMA relation)*)? (
KW_WHERE booleanExpression
whereClause
)?
;

Expand Down Expand Up @@ -563,6 +563,10 @@ columnNamePath
| {this.shouldMatchEmpty()}?
;

columnName
: qualifiedName
;

tableOrViewPath
: tableNamePath
| viewNamePath
Expand Down Expand Up @@ -769,9 +773,15 @@ sortItem
querySpecification
: KW_SELECT setQuantifier? (KW_STRAIGHT_JOIN)? selectItem (COMMA selectItem)* (
KW_FROM relation (COMMA relation)*
)? (KW_WHERE where=booleanExpression)? (KW_GROUP KW_BY groupBy)? (
KW_HAVING having=booleanExpression
)?
)? (whereClause)? (KW_GROUP KW_BY groupBy)? (havingClause)?
;

whereClause
: KW_WHERE where=booleanExpression
;

havingClause
: KW_HAVING having=booleanExpression
;

groupBy
Expand Down Expand Up @@ -933,7 +943,7 @@ primaryExpression
| KW_TRY_CAST LPAREN expression KW_AS type RPAREN # cast
| KW_ARRAY LSQUARE (expression (COMMA expression)*)? RSQUARE # arrayConstructor
| value=primaryExpression LSQUARE index=valueExpression RSQUARE # subscript
| identifier # columnReference
| columnName # columnReference
| base=primaryExpression DOT fieldName=identifier # dereference
| name=KW_CURRENT_DATE # specialDateTimeFunction
| name=KW_CURRENT_TIME (LPAREN precision=INTEGER_VALUE RPAREN)? # specialDateTimeFunction
Expand Down Expand Up @@ -1050,11 +1060,15 @@ whenClause
;

filter
: KW_FILTER LPAREN KW_WHERE booleanExpression RPAREN
: KW_FILTER LPAREN whereClause RPAREN
;

partitionByClause
: partition+=expression (COMMA partition+=expression)*
;

over
: KW_OVER LPAREN (KW_PARTITION KW_BY partition+=expression (COMMA partition+=expression)*)? (
: KW_OVER LPAREN (KW_PARTITION KW_BY partitionByClause)? (
KW_ORDER KW_BY sortItem (COMMA sortItem)*
)? windowFrame? RPAREN
;
Expand Down Expand Up @@ -1093,7 +1107,7 @@ privilege
| KW_CREATE
| KW_INSERT
| KW_REFRESH
| KW_SELECT (LPAREN columnName=identifier RPAREN)?
| KW_SELECT (LPAREN name=identifier RPAREN)?
;

objectType
Expand Down
55 changes: 29 additions & 26 deletions src/grammar/postgresql/PostgreSqlParser.g4
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
/*
* [The "MIT license"]
* Copyright (C) 2014 Sam Harwell, Tunnel Vision Laboratories, LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* [The "MIT license"] Copyright (C) 2014 Sam Harwell, Tunnel Vision Laboratories, LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 2. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
* 3. Except as contained in this notice, the name of Tunnel Vision
* Laboratories, LLC. shall not be used in advertising or otherwise to
* promote the sale, use or other dealings in this Software without prior
* written authorization from Tunnel Vision Laboratories, LLC.
*
* 1. The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software. 2. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
* ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. 3. Except as contained in this notice, the name of Tunnel Vision
* Laboratories, LLC. shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from Tunnel Vision
* Laboratories, LLC.
*/

/**
* This file is an adaptation of antlr's sql/postgresql/PostgreSQLParser.g4 grammar.
* Reference: https://github.com/antlr/grammars-v4/blob/master/sql/postgresql/PostgreSQLParser.g4
* This file is an adaptation of antlr's sql/postgresql/PostgreSQLParser.g4 grammar. Reference:
* https://github.com/antlr/grammars-v4/blob/master/sql/postgresql/PostgreSQLParser.g4
*/

/**
Expand Down Expand Up @@ -2409,7 +2404,7 @@ primaryExpression
| explicit_row
| OPEN_PAREN expression COMMA expr_list CLOSE_PAREN
| row KW_OVERLAPS row
| qualified_name
| column_name_path
| primaryExpression TYPECAST typename
| (PLUS | MINUS) primaryExpression
| primaryExpression qual_op primaryExpression?
Expand Down Expand Up @@ -2504,6 +2499,10 @@ window_clause
: KW_WINDOW window_definition (COMMA window_definition)*
;

having_clause
: KW_HAVING expression
;

window_definition
: colid KW_AS window_specification
;
Expand Down Expand Up @@ -2743,6 +2742,10 @@ column_name
| {this.shouldMatchEmpty()}? # columnNameMatch
;

column_name_path
: colid opt_indirection
;

column_name_create
: colid # columnNameCreate
;
Expand Down Expand Up @@ -3631,5 +3634,5 @@ any_identifier
;

sql_expression
: target_list? into_clause? from_clause? where_clause? group_clause? (KW_HAVING expression)? window_clause?
: target_list? into_clause? from_clause? where_clause? group_clause? having_clause? window_clause?
;
36 changes: 24 additions & 12 deletions src/grammar/spark/SparkSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ columnName
| {this.shouldMatchEmpty()}?
;

columnNamePath
: multipartIdentifier
;

columnNameSeq
: columnName (COMMA columnName)*
;
Expand All @@ -469,11 +473,23 @@ identifierReference
;

queryOrganization
: (KW_ORDER KW_BY order+=sortItem (COMMA order+=sortItem)*)? (
KW_CLUSTER KW_BY clusterBy+=expression (COMMA clusterBy+=expression)*
)? (KW_DISTRIBUTE KW_BY distributeBy+=expression (COMMA distributeBy+=expression)*)? (
KW_SORT KW_BY sort+=sortItem (COMMA sort+=sortItem)*
)? windowClause? (KW_LIMIT (KW_ALL | limit=expression))? (KW_OFFSET offset=expression)?
: (KW_ORDER KW_BY orderOrSortByClause)? (KW_CLUSTER KW_BY clusterOrDistributeBy)? (
KW_DISTRIBUTE KW_BY clusterOrDistributeBy
)? (KW_SORT KW_BY orderOrSortByClause)? windowClause? limitClause? (
KW_OFFSET offset=expression
)?
;

limitClause
: KW_LIMIT (KW_ALL | limit=expression)
;

orderOrSortByClause
: sortItem (COMMA sortItem)*
;

clusterOrDistributeBy
: expression (COMMA expression)*
;

multiInsertQueryBody
Expand Down Expand Up @@ -825,11 +841,7 @@ tableArgumentPartitioning
| partition+=expression
)
)
) (
(KW_ORDER | KW_SORT) KW_BY (
((LEFT_PAREN sortItem (COMMA sortItem)* RIGHT_PAREN) | sortItem)
)
)?
) ((KW_ORDER | KW_SORT) KW_BY ( ((LEFT_PAREN orderOrSortByClause RIGHT_PAREN) | sortItem)))?
;

functionTableNamedArgumentExpression
Expand Down Expand Up @@ -1013,7 +1025,7 @@ primaryExpression
| identifier ARROW expression
| LEFT_PAREN identifier (COMMA identifier)+ RIGHT_PAREN ARROW expression
| value=primaryExpression LEFT_BRACKET index=valueExpression RIGHT_BRACKET
| identifier
| columnNamePath
| base=primaryExpression DOT fieldName=identifier
| LEFT_PAREN expression RIGHT_PAREN
| KW_EXTRACT LEFT_PAREN field=identifier KW_FROM source=valueExpression RIGHT_PAREN
Expand Down Expand Up @@ -1286,7 +1298,7 @@ windowSpec
(KW_PARTITION | KW_DISTRIBUTE) KW_BY partition+=expression (
COMMA partition+=expression
)*
)? ((KW_ORDER | KW_SORT) KW_BY sortItem (COMMA sortItem)*)?
)? ((KW_ORDER | KW_SORT) KW_BY orderOrSortByClause)?
) windowFrame? RIGHT_PAREN
;

Expand Down
Loading
Loading