Skip to content

RowBinary writer for ease of serialization #2190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 16, 2025
Merged
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
@@ -29,6 +29,8 @@ public class RowBinaryFormatWriter {

private final Object[] row;

private final boolean defaultSupport;

public RowBinaryFormatWriter(OutputStream out, TableSchema tableSchema, ClickHouseFormat format) {
if (format != ClickHouseFormat.RowBinary && format != ClickHouseFormat.RowBinaryWithDefaults) {
throw new IllegalArgumentException("Only RowBinary and RowBinaryWithDefaults are supported");
@@ -37,6 +39,7 @@ public RowBinaryFormatWriter(OutputStream out, TableSchema tableSchema, ClickHou
this.out = out;
this.tableSchema = tableSchema;
this.row = new Object[tableSchema.getColumns().size()];
this.defaultSupport = format == ClickHouseFormat.RowBinaryWithDefaults;
}

public void setValue(String column, Object value) {
@@ -48,12 +51,11 @@ public void setValue(int colIndex, Object value) {
}

public void commitRow() throws IOException {

List<ClickHouseColumn> columnList = tableSchema.getColumns();
for (int i = 0; i < row.length; i++) {
ClickHouseColumn column = columnList.get(i);

if (RowBinaryFormatSerializer.writeValuePreamble(out, true, column, row[i])) {
if (RowBinaryFormatSerializer.writeValuePreamble(out, defaultSupport, column, row[i])) {
SerializerUtils.serializeData(out, row[i], column);
}
}
Original file line number Diff line number Diff line change
@@ -205,9 +205,12 @@ public <T> T readValue(ClickHouseColumn column, Class<?> typeHint) throws IOExce
return (T) readGeoPolygon();
case MultiPolygon:
return (T) readGeoMultiPolygon();
case MultiLineString:
return (T) readGeoPolygon();
case Ring:
return (T) readGeoRing();

case LineString:
return (T) readGeoRing();
case JSON: // experimental https://clickhouse.com/docs/en/sql-reference/data-types/newjson
if (jsonAsString) {
return (T) readString(input);
Original file line number Diff line number Diff line change
@@ -80,10 +80,12 @@ public static void serializeData(OutputStream stream, Object value, ClickHouseCo
serializeTupleData(stream, value, GEO_POINT_TUPLE);
break;
case Ring:
case LineString:
value = value instanceof ClickHouseGeoRingValue ? ((ClickHouseGeoRingValue)value).getValue() : value;
serializeArrayData(stream, value, GEO_RING_ARRAY);
break;
case Polygon:
case MultiLineString:
value = value instanceof ClickHouseGeoPolygonValue ? ((ClickHouseGeoPolygonValue)value).getValue() : value;
serializeArrayData(stream, value, GEO_POLYGON_ARRAY);
break;

Large diffs are not rendered by default.