Skip to content
Open
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 @@ -283,6 +283,12 @@ public String convertParameterToString(Object value) {
// the value). Escape those three characters so any String value round-trips.
return escapeStringParameter((CharSequence) value);
}
if (value instanceof LocalDateTime) {
return DataTypeUtils.DATETIME_WITH_NANOS_FORMATTER.format((LocalDateTime) value);
}
if (value instanceof LocalTime) {
return DataTypeUtils.TIME_WITH_NANOS_FORMATTER.format((LocalTime) value);
}
// Other scalars have no escapable characters and are read verbatim by the server, so they
// are passed through unquoted (e.g. Date, numbers, Identifier).
return String.valueOf(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ public static Object[][] queryParameters() {
// --- Scalars: bare, UNQUOTED text form. The server reads a scalar {name:Type} value
// verbatim, so quoting it (e.g. '2026-05-13' for a Date) is rejected. ---
{LocalDate.of(2026, 5, 13), "2026-05-13"},
{LocalDateTime.of(2026, 11, 19, 0, 0), "2026-11-19 00:00:00"},
{LocalDateTime.of(2026, 11, 19, 12, 34, 56), "2026-11-19 12:34:56"},
{LocalDateTime.of(2026, 11, 19, 12, 34, 0, 500_000_000), "2026-11-19 12:34:00.5"},
{LocalTime.of(9, 0), "09:00:00"},
{LocalTime.of(12, 34, 56), "12:34:56"},
{LocalTime.of(12, 34, 0, 500_000_000), "12:34:00.5"},
{"hello", "hello"},
{42, "42"},
{new BigDecimal("1.50"), "1.50"},
Expand Down Expand Up @@ -288,4 +294,4 @@ public void testConvertDeeplyNestedParameterDoesNotOverflow() {

assertEquals(new DataTypeConverter().convertParameterToString(nested), expected.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -1864,6 +1865,26 @@ public void testContainerQueryParamsQuoteInnerValues(String clickHouseType, Obje
Assert.assertEquals(records.get(0).getString("v"), expected);
}

@DataProvider(name = "scalarTemporalQueryParameters")
Object[][] scalarTemporalQueryParameters() {
return new Object[][]{
{"DateTime('UTC')", LocalDateTime.of(2026, 11, 19, 0, 0), "2026-11-19 00:00:00"},
{"DateTime64(9, 'UTC')", LocalDateTime.of(2026, 11, 19, 12, 34, 0, 123_456_789), "2026-11-19 12:34:00.123456789"},
{"Time", LocalTime.of(9, 0), "09:00:00"},
{"Time64(3)", LocalTime.of(12, 34, 0, 500_000_000), "12:34:00.500"},
};
}

@Test(groups = {"integration"}, dataProvider = "scalarTemporalQueryParameters")
public void testScalarTemporalQueryParamsRoundTrip(String clickHouseType, Object value, String expected) {
QuerySettings settings = new QuerySettings().serverSetting("allow_experimental_time_time64_type", "1");
Map<String, Object> params = Collections.singletonMap("p", value);
List<GenericRecord> records = client.queryAll("SELECT toString({p:" + clickHouseType + "}) AS v", params, settings);

Assert.assertEquals(records.size(), 1);
Assert.assertEquals(records.get(0).getString("v"), expected);
}

@DataProvider(name = "scalarStringQueryParameters")
Object[][] scalarStringQueryParameters() {
// Scalar {p:String} values that must round-trip byte-for-byte through the server's
Expand Down
1 change: 1 addition & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This document lists stable, user-visible behavior in `client-v2` and `jdbc-v2` t
Compatibility-sensitive traits:

- Named parameter typing is part of the contract: placeholders are written as `{name:Type}` and the supplied value must match the expected ClickHouse textual representation for that type.
- Scalar `LocalDateTime` and `LocalTime` query parameters always include the seconds field and preserve non-zero fractional seconds, matching the ClickHouse `DateTime`/`DateTime64` and `Time`/`Time64` textual forms.
- String query parameters are expected to round-trip correctly for ordinary text, Unicode, slashes, dashes, leading or trailing spaces, and characters the server's escaped-text parameter parser treats as structural — a backslash, tab, or newline — which the client escapes before sending.
- A `null` query-parameter value is sent as the ClickHouse `\N` NULL sentinel, so a top-level `{name:Nullable(T)}` placeholder binds SQL `NULL`; a `null` nested inside an `Array`/`Map` parameter value renders as the SQL `NULL` keyword.
- Runtime authentication changes are compatibility-sensitive: after `updateUserAndPassword()`, `updateAccessToken()`, or `updateBearerToken()`, subsequent requests from the same `Client` are expected to use the updated credentials. The authentication method itself is fixed at construction time; calling a runtime updater that does not match the configured method throws `ClientMisconfigurationException`.
Expand Down
4 changes: 4 additions & 0 deletions history/latest/3387.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- **[client-v2]** Scalar `LocalDateTime` and `LocalTime` query parameters now always include seconds
and preserve non-zero fractional seconds. Zero-second `DateTime` values no longer fail to parse,
and zero-second `Time` values no longer bind as minutes and seconds.
(https://github.com/ClickHouse/clickhouse-java/issues/3387)