clickhouse-java
clickhouse-java copied to clipboard
Passing an Instant as a query parameter in client-v2 fails during parsing
Description
The API for query parameters with an Instant generates a query which can not be parsed by the server.
Steps to reproduce
See example below.
Error Log or Exception StackTrace
com.clickhouse.client.api.ServerException: Code: 457. DB::Exception: Value 2025-06-16T11:54:26.413588562Z cannot be parsed as DateTime64 for query parameter 'year_start' because it isn't parsed completely: only 29 of 30 bytes was parsed: 2025-06-16T11:54:26.413588562. (BAD_QUERY_PARAMETER) (version 25.3.3.42 (official build))
Expected Behaviour
It should work smoothly.
Code Example
@Test
void testParamsWithInstant() throws Exception {
final Client client = new Client.Builder()
.addEndpoint(Protocol.HTTP, "localhost", 8123, false)
.setUsername("default")
.setPassword("")
.build();
final Map<String, Object> params = Map.of("year_start", Instant.now());
// This query should not throw an exception
client.query("SELECT * FROM system.tables WHERE metadata_modification_time < {year_start:DateTime64}", params).get();
}
Test is passing when serializing the parameter to a String, e.g. "2025-06-16 11:54:26.413588562".
A related query with an array also fails with the following parsing error:
com.clickhouse.client.api.ServerException: Code: 130. DB::Exception: Cannot read array from text, expected comma or end of array, found '-': value [2025-06-16T12:03:29.844112439Z] cannot be parsed as Array(DateTime64) for query parameter 'year_start'. (CANNOT_READ_ARRAY_FROM_TEXT) (version 25.3.3.42 (official build))
The error above was done with:
final Map<String, Object> params = Map.of("year_start", List.of(Instant.now()));
// This query should not throw an exception
client.query("SELECT * FROM system.tables WHERE metadata_modification_time in {year_start:Array(DateTime64)}", params).get();
Configuration
Client Configuration
See above.
Environment
- [ ] Cloud
- Client version:
- Language version:
- OS:
ClickHouse Server
- ClickHouse Server version: 25.3.3.42
- ClickHouse Server non-default settings, if any:
CREATE TABLEstatements for tables involved:- Sample data for all these tables, use clickhouse-obfuscator if necessary