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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ query

// CTE statement
ctes
: LPAREN? WITH (cteUnboundCol COMMA)* namedQuery (COMMA namedQuery)* RPAREN?
: LPAREN? WITH cteUnboundCol? (COMMA cteUnboundCol)* COMMA? namedQuery (COMMA namedQuery)* RPAREN?
;

namedQuery
Expand All @@ -55,6 +55,8 @@ columnAliases
cteUnboundCol
: (literal AS identifier) # CteUnboundColLiteral
| (QUERY AS identifier) # CteUnboundColParam
| LPAREN columnExpr RPAREN AS identifier # CteUnboundColExpr
| LPAREN ctes? selectStmt RPAREN AS identifier # CteUnboundNestedSelect
;

// ALTER statement
Expand Down Expand Up @@ -438,6 +440,11 @@ fromClause
: FROM joinExpr
| FROM identifier LPAREN QUERY RPAREN
| FROM ctes
| FROM identifier LPAREN viewParam (COMMA viewParam)? RPAREN
;

viewParam
: identifier EQ_SINGLE (literal | QUERY)
;

arrayJoinClause
Expand Down Expand Up @@ -937,6 +944,7 @@ columnExpr
| LBRACKET columnExprList? RBRACKET # ColumnExprArray
| columnIdentifier # ColumnExprIdentifier
| QUERY (CAST_OP identifier)? # ColumnExprParam
| columnExpr REGEXP literal # ColumnExprRegexp
;

columnArgList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ public void enterFromClause(ClickHouseParser.FromClauseContext ctx) {
}
}

@Override
public void enterViewParam(ClickHouseParser.ViewParamContext ctx) {
if (ctx.QUERY() != null) {
appendParameter(ctx.QUERY().getSymbol().getStartIndex());
}
}

private void appendParameter(int startIndex) {
argCount++;
if (argCount > paramPositions.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ public Object[][] testMiscStmtDp() {
{"SELECT v FROM t WHERE f in (?)", 1},
{"SELECT v FROM t WHERE a > 10 AND event NOT IN (?)", 1},
{"SELECT v FROM t WHERE f in (1, 2, 3)", 0},
{"with ? as val1, numz as (select val1, number from system.numbers limit 10) select * from numz", 1}
{"with ? as val1, numz as (select val1, number from system.numbers limit 10) select * from numz", 1},
{"WITH 'hello' REGEXP 'h' AS result SELECT 1", 0},
{"WITH (select 1) as a, z AS (select 2) SELECT 1", 0},
{"SELECT result FROM test_view(myParam = ?)", 1},
};
}

Expand Down