Skip to content

Feat/column entity #434

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

Draft
wants to merge 4 commits into
base: next
Choose a base branch
from
Draft
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
54 changes: 45 additions & 9 deletions src/grammar/flink/FlinkSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,34 @@ selectStatement
;

selectClause
: KW_SELECT setQuantifier? (
ASTERISK_SIGN
| projectItemDefinition (COMMA projectItemDefinition)*
)
: KW_SELECT setQuantifier? selectList
;

selectList
: columnProjectItem (COMMA columnProjectItem)*
;

columnProjectItem
: selectWindowItemColumnName
| selectLiteralColumnName (columnAlias | KW_AS? expression)?
| selectExpressionColumnName (columnAlias | KW_AS? columnName)?
| tableAllColumns columnAlias?
;

selectWindowItemColumnName
: overWindowItem
;

selectExpressionColumnName
: expression
;

selectLiteralColumnName
: columnName
;

columnAlias
: KW_AS? alias=identifier
;

projectItemDefinition
Expand All @@ -495,9 +519,13 @@ projectItemDefinition
| columnName (KW_AS? expression)?
;

tableAllColumns
: (identifier (DOT identifier)* DOT)? ASTERISK_SIGN
;

overWindowItem
: primaryExpression KW_OVER windowSpec KW_AS identifier
| primaryExpression KW_OVER errorCapturingIdentifier KW_AS identifier
: primaryExpression KW_OVER windowSpec KW_AS alias=identifier
| primaryExpression KW_OVER errorCapturingIdentifier KW_AS alias=identifier
;

fromClause
Expand All @@ -519,8 +547,16 @@ tableReference
tablePrimary
: KW_TABLE? tablePath systemTimePeriod?
| viewPath systemTimePeriod?
| KW_LATERAL KW_TABLE LR_BRACKET functionCallExpression RR_BRACKET
| KW_LATERAL? LR_BRACKET queryStatement RR_BRACKET
| atomFunctionTable
| atomExpressionTable
;

atomFunctionTable
: KW_LATERAL KW_TABLE LR_BRACKET functionCallExpression RR_BRACKET
;

atomExpressionTable
: KW_LATERAL? LR_BRACKET queryStatement RR_BRACKET
| KW_UNNEST LR_BRACKET expression RR_BRACKET
;

Expand Down Expand Up @@ -939,7 +975,7 @@ viewPathCreate
;

uid
: identifier (DOT identifier)*?
: identifier (DOT identifier)*
;

withOption
Expand Down
38 changes: 30 additions & 8 deletions src/grammar/hive/HiveSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ viewNameCreate
;

subQuerySource
: LPAREN queryStatementExpression RPAREN KW_AS? id_
: LPAREN queryStatementExpression RPAREN KW_AS? alias=id_
;

/**
Expand All @@ -1455,9 +1455,13 @@ partitionTableFunctionSource
;

partitionedTableFunction
: atomPartitionedTableFunction alias=id_?
;

atomPartitionedTableFunction
: n=id_ LPAREN KW_ON ptfsrc=partitionTableFunctionSource spec=partitioningSpec? (
Identifier LPAREN expression RPAREN (COMMA Identifier LPAREN expression RPAREN)*
)? RPAREN alias=id_?
)? RPAREN
;

/**
Expand Down Expand Up @@ -1485,23 +1489,24 @@ valuesClause
)
;

atomValuesClause
: KW_TABLE LPAREN valuesClause RPAREN
;

/*
This represents a clause like this:
TABLE(VALUES(1,2),(2,3)) as VirtTable(col1,col2)
*/
virtualTableSource
: KW_TABLE LPAREN valuesClause RPAREN KW_AS? tableAlias (LPAREN id_ (COMMA id_)*)? RPAREN
: atomValuesClause KW_AS? alias=tableAlias (LPAREN id_ (COMMA id_)*)? RPAREN
;

/*
Rules for parsing selectClause
select a,b,c ...
*/
selectClause
: KW_SELECT QUERY_HINT? (
(KW_ALL | KW_DISTINCT)? selectItem (COMMA selectItem)*
| KW_TRANSFORM selectTrfmClause
)
: KW_SELECT QUERY_HINT? ((KW_ALL | KW_DISTINCT)? selectList | KW_TRANSFORM selectTrfmClause)
| trfmClause
;

Expand All @@ -1511,9 +1516,26 @@ selectTrfmClause
)? rowFormat recordReader
;

selectList
: selectItem (COMMA selectItem)*
;

selectItem
: tableAllColumns
| ((columnName | expression) (KW_AS? id_ | KW_AS LPAREN id_ (COMMA id_)* RPAREN)?)
| (
(selectLiteralColumnName | selectExpressionColumnName) (
KW_AS? alias=id_
| KW_AS LPAREN alias=id_ (COMMA alias=id_)* RPAREN
)?
)
;

selectLiteralColumnName
: columnName
;

selectExpressionColumnName
: expression
;

trfmClause
Expand Down
38 changes: 31 additions & 7 deletions src/grammar/impala/ImpalaSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,13 @@ sortItem
;

querySpecification
: KW_SELECT setQuantifier? (KW_STRAIGHT_JOIN)? selectItem (COMMA selectItem)* (
KW_FROM relation (COMMA relation)*
)? (whereClause)? (KW_GROUP KW_BY groupBy)? (havingClause)?
: KW_SELECT setQuantifier? (KW_STRAIGHT_JOIN)? selectList (KW_FROM relation (COMMA relation)*)? (
whereClause
)? (KW_GROUP KW_BY groupBy)? (havingClause)?
;

selectList
: selectItem (COMMA selectItem)*
;

whereClause
Expand Down Expand Up @@ -807,9 +811,25 @@ setQuantifier
;

selectItem
: columnItem (KW_AS? identifier)? # selectSingle
| qualifiedName DOT ASTERISK # selectAll
| ASTERISK # selectAll
: selectLiteralColumnName columnAlias?
| selectExpressionColumnName columnAlias?
| tableAllColumns columnAlias?
;

columnAlias
: KW_AS alias=identifier
;

selectLiteralColumnName
: columnNamePath columnAlias?
;

selectExpressionColumnName
: expression
;

tableAllColumns
: (qualifiedName DOT)? ASTERISK
;

relation
Expand Down Expand Up @@ -861,11 +881,15 @@ columnAliases

relationPrimary
: tableOrViewPath
| KW_LATERAL? subQueryRelation
| atomSubQueryTableSource
| unnest
| parenthesizedRelation
;

atomSubQueryTableSource
: KW_LATERAL? subQueryRelation
;

subQueryRelation
: LPAREN queryStatement RPAREN
;
Expand Down
37 changes: 29 additions & 8 deletions src/grammar/mysql/MySqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,14 @@ tableSource
tableSourceItem
: tableName (KW_PARTITION '(' partitionNames ')')? (KW_AS? alias=uid)? (
indexHint (',' indexHint)*
)? # atomTableItem
| KW_LATERAL? (selectStatement | '(' parenthesisSubquery=selectStatement ')') KW_AS? alias=uid fullColumnNames? # subqueryTableItem
| '(' tableSources ')' # tableSourcesItem
)? # atomTableItem
| KW_LATERAL? atomSubQueryTableSource KW_AS? alias=uid fullColumnNames? # subqueryTableItem
| '(' tableSources ')' # tableSourcesItem
;

atomSubQueryTableSource
: selectStatement
| '(' parenthesisSubquery=selectStatement ')'
;

// (col_list) | (col_alias [, col_alias] ...)
Expand Down Expand Up @@ -1196,14 +1201,30 @@ selectSpec
;

selectElements
: (star='*' | selectElement) (',' selectElement)*
: (pureAllColumns | selectElement) (',' selectElement)*
;

selectElement
: (LOCAL_ID VAR_ASSIGN)? expression (KW_AS? alias=uid)? # selectExpressionElement
| functionCall (KW_AS? alias=uid)? # selectFunctionElement
| select_element=fullId '.' '*' # selectStarElement
| columnName (KW_AS? alias=uid)? # selectColumnElement
: tableAllColumns
| selectLiteralColumnName (KW_AS? alias=uid)?
| selectExpressionColumnName (KW_AS? alias=uid)?
;

tableAllColumns
: fullId DOT STAR
;

pureAllColumns
: STAR
;

selectLiteralColumnName
: columnName
;

selectExpressionColumnName
: (LOCAL_ID VAR_ASSIGN)? expression # selectExpressionElement
| functionCall # selectFunctionElement
;

intoClause
Expand Down
24 changes: 15 additions & 9 deletions src/grammar/postgresql/PostgreSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -2113,11 +2113,7 @@ fromList
tableRef
: (
(relationExpr | (KW_ONLY? viewName STAR? columnList? whereClause?)) aliasClause? tableSampleClause?
| KW_LATERAL? (
xmlTable aliasClause?
| funcTable funcAliasClause?
| selectWithParens aliasClause?
)
| KW_LATERAL? expressionTable
| OPEN_PAREN tableRef (
KW_CROSS KW_JOIN tableRef
| KW_NATURAL joinType? KW_JOIN tableRef
Expand All @@ -2130,6 +2126,12 @@ tableRef
)*
;

expressionTable
: xmlTable aliasClause?
| funcTable funcAliasClause?
| selectWithParens aliasClause?
;

aliasClause
: KW_AS? alias=colId (OPEN_PAREN nameList CLOSE_PAREN)?
;
Expand Down Expand Up @@ -2558,8 +2560,8 @@ columnExpr
;

columnExprNoParen
: expression
| columnName
: expression # selectExpressionColumnName
| columnName # selectLiteralColumnName
;

funcArgList
Expand Down Expand Up @@ -2623,8 +2625,12 @@ targetList
;

targetEl
: columnExprNoParen (KW_AS colLabel | identifier |) # target_label
| STAR # target_star
: tableAllColumns # target_star
| columnExprNoParen (KW_AS? alias=identifier |) # target_label
;

tableAllColumns
: (colId DOT)* STAR
;

qualifiedNameList
Expand Down
Loading
Loading