Skip to content

[clickhouse] ambiguity in selectStmt/selectUnionStmt #4623

@kaby76

Description

@kaby76

selectUnionStmt is currently this.

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 in selectUnionStmt : selectStmtWithParens (UNION ALL selectStmtWithParens)* ;, but should be instead the +-operator, selectUnionStmt : selectStmtWithParens (UNION ALL selectStmtWithParens)+ ;
  • Or, the syntax for selectUnionStmt should be subsumed by selectStmt.
  • 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions