clickhouse-java
clickhouse-java copied to clipboard
Why DQL SETTINGS not support placeholder ?
step: sql:select xxx from xxx settings max_execution_time = :max_execution_time params:put("max_execution_time", 3);
result: c.c.jdbc.parser.ClickHouseSqlParser : Parse error at line 1, column 284.
Hi @guosk123, could you share the exact SQL which has the problem? Below works for me:
String sql = "select xxx from xxx settings max_execution_time = :max_execution_time";
request.query(sql).params(Collections.singletonMap("max_execution_time", "3"));
Assert.assertEquals(request.getStatements(false).get(0),
"select xxx from xxx settings max_execution_time = 3");
@zhicwu, the sql is probably like you wrote, can be executed successfully! But, an alert will appear:
2022-08-02 00:00:00.700 WARN 32504 --- [calculate-task] c.c.jdbc.parser.ClickHouseSqlParser : Parse error at line 1, column 397. Encountered: ?. If you believe the SQL is valid, please feel free to open an issue on Github with this warning and the following SQL attached. select SUM(total_bytes) AS totalBytes from d_fpc_metric_network_data_record_1h where 1 = 1 and ((timestamp > toDateTime64(?, 3, 'UTC') and timestamp <= toDateTime64(?, 3, 'UTC')) or (timestamp > toDateTime64(?, 3, 'UTC') and timestamp <= toDateTime64(?, 3, 'UTC'))) and network_id in (?, ?, ?, ?, ?, ?, ?, ?) GROUP BY timestamp ORDER BY timestamp LIMIT 10000 settings max_execution_time = ?
When I modify it to(don't use placeholder):String sql = "select xxx from xxx settings max_execution_time = 3", back to normal~~
Thanks @guosk123. I'll fix the issue in ClickHouseSqlParser.