clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

Why DQL SETTINGS not support placeholder ?

Open guosk123 opened this issue 3 years ago • 3 comments

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.

guosk123 avatar Aug 02 '22 08:08 guosk123

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 avatar Aug 03 '22 08:08 zhicwu

@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~~

guosk123 avatar Aug 03 '22 09:08 guosk123

Thanks @guosk123. I'll fix the issue in ClickHouseSqlParser.

zhicwu avatar Aug 06 '22 02:08 zhicwu