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
7 changes: 4 additions & 3 deletions jdbc-v2/src/main/javacc/ClickHouseSqlParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ void columnExpr(): { Token t; } {
| (LOOKAHEAD(2) macro())+
| LOOKAHEAD(2, { !(tokenIn(1, INF, NAN, NULL) && tokenIn(2, DOT)) }) literal()
| LOOKAHEAD(2, { getToken(2).kind == LPAREN }) functionExpr() { token_source.funcUsed = true; }
| anyIdentifier() (LOOKAHEAD(2) <DOT> anyIdentifier())*
| anyIdentifier() (LOOKAHEAD(2) <DOT> (<CARET>)? anyIdentifier())*
}

// interested parts
Expand Down Expand Up @@ -930,7 +930,7 @@ Token aliasExpr(): { Token t = null; } {
}

void nestedIdentifier(): {} {
(<ASTERISK> | anyIdentifier()) (LOOKAHEAD(2) <DOT> (<ASTERISK> | anyIdentifier()))*
(<ASTERISK> | anyIdentifier()) (LOOKAHEAD(2) <DOT> (<CARET>)? (<ASTERISK> | anyIdentifier()))*
}

void tableIdentifier(boolean record): { } {
Expand Down Expand Up @@ -1029,7 +1029,7 @@ Token numberLiteral(): { Token t = null; StringBuilder sb = new StringBuilder();
}

void operator(): {} {
(<ARROW> | <ASTERISK> | <CONCAT> | <CONVERT> | <DASH> | <EQ_DOUBLE> | <EQ_SINGLE>
(<ARROW> | <ASTERISK> | <CARET> | <CONCAT> | <CONVERT> | <DASH> | <EQ_DOUBLE> | <EQ_SINGLE>
| <GE> | <GT> | <LE> | <LT> | <NOT_EQ> | <PERCENT> | <PLUS> | <SLASH>)
}

Expand Down Expand Up @@ -1286,6 +1286,7 @@ TOKEN: {
| <RPAREN: ")">
| <SEMICOLON: ";">
| <SLASH: "/">
| <CARET: "^">
| <#UNDERSCORE: "_">
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ public Object[][] testMiscStmtDp() {
{"select countIf(*, 1 = ?)", 1},
{"select count(*) filter (where 1 = ?)", 1},
{WHEN_HAS_ARRAY, 0},
{EXTEND_JOIN_ALIAS_SYNTAX, 0},
{"SELECT * FROM t WHERE hasToken(message, 'DDLWorker')", 0},
{"SELECT * FROM t WHERE hasAllTokens(message, ['peak', 'memory'])", 0},
{"SELECT * FROM t WHERE hasAnyTokens(message, tokens('01442_merge_detach_attach'))", 0},
};
}

Expand Down Expand Up @@ -569,6 +573,11 @@ public Object[][] testMiscStmtDp() {
" END AS action_to_do\n" +
"FROM db.table1";

private static final String EXTEND_JOIN_ALIAS_SYNTAX = "SELECT *\n" +
"FROM (SELECT 1) AS t(a)\n" +
"JOIN (SELECT 1) AS u(b)\n" +
"ON a = b";

@Test(dataProvider = "testStatementWithoutResultSetDP")
public void testStatementsForResultSet(String sql, int args, boolean hasResultSet) {
System.out.println("sql: " + sql);
Expand Down Expand Up @@ -652,7 +661,8 @@ public static Object[][] testStatementWithoutResultSetDP() {
{"CHECK GRANT SELECT(col2) ON table_2", 0, true},
{"CHECK TABLE test_table", 0, true},
{"CHECK TABLE t0 PARTITION ID '201003' FORMAT PrettyCompactMonoBlock SETTINGS check_query_single_value_result = 0", 0, true},

{"select toJSONString(data.^header_index) from database.analyzed limit 1;", 0, true},
{"select toJSONString(data.^header_index), ? as text from database.analyzed limit 1;", 1, true},

/* no result set */
{"INSERT INTO test_table VALUES (1, ?)", 1, false},
Expand Down