-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Labels
Description
selectUnionStmt is currently this.
grammars-v4/sql/clickhouse/ClickHouseParser.g4
Lines 387 to 394 in e83e826
selectUnionStmt | |
: selectStmtWithParens (UNION ALL selectStmtWithParens)* | |
; | |
selectStmtWithParens | |
: selectStmt | |
| LPAREN selectUnionStmt RPAREN | |
; |
Select statements are parsed in two ways, via selectUnionStmt or selectStmt.
The problem is that examples/select.sql then has two ways to parse the select statement.
../examples/select.sql.d=8.a=12: (clickhouseFile (batch (command (query (selectUnionStmt (selectStmtWithParens (selectStmt (SELECT "SELECT") (columnExprList (columnsExpr (columnExpr (identifier (IDENTIFIER "COLUMNS")) (LPAREN "(") (columnArgList (columnArgExpr (columnExpr (literal (STRING_LITERAL "'a'"))))) (RPAREN ")"))) (COMMA ",") (columnsExpr (columnExpr (identifier (IDENTIFIER "COLUMNS")) (LPAREN "(") (columnArgList (columnArgExpr (columnExpr (literal (STRING_LITERAL "'c'"))))) (RPAREN ")"))) (COMMA ",") (columnsExpr (columnExpr (identifier (IDENTIFIER "toTypeName")) (LPAREN "(") (columnArgList (columnArgExpr (columnExpr (identifier (IDENTIFIER "COLUMNS")) (LPAREN "(") (columnArgList (columnArgExpr (columnExpr (literal (STRING_LITERAL "'c'"))))) (RPAREN ")")))) (RPAREN ")")))) (fromClause (FROM "FROM") (joinExpr (tableExpr (tableIdentifier (identifier (IDENTIFIER "col_names")))))))))))) (EOF ""))
../examples/select.sql.d=8.a=19: (clickhouseFile (batch (command (query (selectStmt (SELECT "SELECT") (columnExprList (columnsExpr (columnExpr (identifier (IDENTIFIER "COLUMNS")) (LPAREN "(") (columnArgList (columnArgExpr (columnExpr (literal (STRING_LITERAL "'a'"))))) (RPAREN ")"))) (COMMA ",") (columnsExpr (columnExpr (identifier (IDENTIFIER "COLUMNS")) (LPAREN "(") (columnArgList (columnArgExpr (columnExpr (literal (STRING_LITERAL "'c'"))))) (RPAREN ")"))) (COMMA ",") (columnsExpr (columnExpr (identifier (IDENTIFIER "toTypeName")) (LPAREN "(") (columnArgList (columnArgExpr (columnExpr (identifier (IDENTIFIER "COLUMNS")) (LPAREN "(") (columnArgList (columnArgExpr (columnExpr (literal (STRING_LITERAL "'c'"))))) (RPAREN ")")))) (RPAREN ")")))) (fromClause (FROM "FROM") (joinExpr (tableExpr (tableIdentifier (identifier (IDENTIFIER "col_names")))))))))) (EOF ""))
The error is one of two ways:
selectUnionStmt
is wrong. It should not be using the*
-operator inselectUnionStmt : selectStmtWithParens (UNION ALL selectStmtWithParens)* ;
, but should be instead the+
-operator,selectUnionStmt : selectStmtWithParens (UNION ALL selectStmtWithParens)+ ;
- Or, the syntax for
selectUnionStmt
should be subsumed byselectStmt
. - Or,
query
is wrong. It should only have one alt to parse a select statement, i.e.,| ctes? selectUnionStmt
.
Unclear what the grammar should be. In the "Doc", there's only a "SELECT Query", no "SELECT UNION Query". (There's no readme.md to say whether I'm even referencing the right documentation. Please provide a readme.md so people can understand what grammar is being implemented here.)
cc: @mlorek @wangyang377