Skip to content

Commit 4d4fc7b

Browse files
committed
Fixed tuples
1 parent aaffb6f commit 4d4fc7b

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

client-v2/src/main/java/com/clickhouse/client/api/data_formats/JSONEachRowFormatReader.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,14 @@ public Object[] getTuple(int index) {
429429

430430
@Override
431431
public Object[] getTuple(String colName) {
432-
return (Object[]) currentRow.get(colName);
432+
Object value = currentRow.get(colName);
433+
if (value == null) {
434+
return null;
435+
}
436+
if (value instanceof List<?>) {
437+
return ((List<?>) value).toArray(new Object[0]);
438+
}
439+
return (Object[]) value;
433440
}
434441

435442
@Override

client-v2/src/test/java/com/clickhouse/client/api/data_formats/JSONEachRowFormatReaderTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ public void testUuidAndListAccessors() throws Exception {
401401
UUID uuid = UUID.fromString("11111111-2222-3333-4444-555555555555");
402402
try (JSONEachRowFormatReader reader = readerOf(row(
403403
"u", uuid.toString(),
404-
"arr", Arrays.asList(1, 2, 3)))) {
404+
"arr", Arrays.asList(1, 2, 3),
405+
"tuple", Arrays.asList("a", 1)))) {
405406
reader.next();
406407

407408
Assert.assertEquals(reader.getUUID("u"), uuid);
@@ -410,6 +411,9 @@ public void testUuidAndListAccessors() throws Exception {
410411
List<Integer> list = reader.getList("arr");
411412
Assert.assertEquals(list, Arrays.asList(1, 2, 3));
412413
Assert.assertEquals(reader.<Integer>getList(2), Arrays.asList(1, 2, 3));
414+
415+
Assert.assertEquals(reader.getTuple("tuple"), new Object[] {"a", 1});
416+
Assert.assertEquals(reader.getTuple(3), new Object[] {"a", 1});
413417
}
414418
}
415419

docs/client-v2-json-support.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ Behavior:
311311
the `List` implementation produced by the selected JSON library. Because
312312
`JSONEachRow` has no array element metadata, `ResultSet.getArray(...)` is
313313
not supported for these inferred JSON arrays.
314+
- Temporal typed JDBC accessors follow the current `JSONEachRowFormatReader`
315+
text-accessor support. `ResultSet.getString(...)` can be used to read the
316+
server-formatted temporal text, but `getTimestamp(...)`,
317+
`getObject(..., Timestamp.class)`, and related temporal conversions are not
318+
guaranteed for `FORMAT JSONEachRow` result sets. Use the binary default
319+
format when JDBC temporal typed accessors are required, or read the value as
320+
a string/object and convert it in application code.
314321
- The JSON processor is selected at the connection level through the
315322
`jdbc_json_parser_factory` driver property. It cannot be changed per
316323
statement, in line with the lifecycle of other connection options.

docs/features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Compatibility-sensitive traits:
8080
- String-like ClickHouse values have stable JDBC expectations: `String`, `FixedString`, and `Enum` values are returned as strings, while `UUID` is available both as `getString()` and `getObject(..., UUID.class)`.
8181
- `Geometry` has a stable JDBC mapping: metadata reports SQL type `ARRAY` with type name `Geometry`, read paths return nested Java arrays rather than custom wrappers, and write paths depend on the caller preserving the intended point/array nesting shape.
8282
- JDBC `Geometry` writes share the same ambiguity as the client serializer: variant selection is inferred from nesting depth, so `Ring` versus `LineString` and `Polygon` versus `MultiLineString` are not currently distinguishable when writing through the generic `Geometry` path.
83-
- JDBC `FORMAT JSONEachRow` support is opt-in through the `jdbc_json_parser_factory` driver property, whose value must be a fully-qualified `JsonParserFactory` class name with a public no-argument constructor; JSONEachRow numeric and structured value behavior follows the selected parser and configured server output settings. Inferred JSON arrays are returned from `ResultSet.getObject(...)` as parser-native `List` values rather than JDBC `Array` values because JSONEachRow does not include element metadata.
83+
- JDBC `FORMAT JSONEachRow` support is opt-in through the `jdbc_json_parser_factory` driver property, whose value must be a fully-qualified `JsonParserFactory` class name with a public no-argument constructor; JSONEachRow numeric and structured value behavior follows the selected parser and configured server output settings. Inferred JSON arrays are returned from `ResultSet.getObject(...)` as parser-native `List` values rather than JDBC `Array` values because JSONEachRow does not include element metadata. JDBC temporal typed accessors such as `getTimestamp(...)` are not guaranteed for JSONEachRow result sets; callers that need stable JDBC temporal conversions should use the binary default format or perform application-level conversion from string/object values.
8484
- Binary parameters passed through `setBytes()` are encoded as ClickHouse `unhex(...)` expressions rather than text literals; empty byte arrays map to an empty string expression.
8585
- Stream and reader setters (`setAsciiStream`, `setUnicodeStream`, `setBinaryStream`, `setCharacterStream`, `setNCharacterStream`) are treated as text input encoded with the same string-escaping rules, including length-based truncation when a length is supplied.
8686
- `getString()` formatting for temporal values is stable output: `Date` uses `yyyy-MM-dd`, `DateTime` uses `yyyy-MM-dd HH:mm:ss`, and `DateTime64` preserves fractional precision, all interpreted in server timezone context where applicable.

0 commit comments

Comments
 (0)