From e0720396ad518b24f0328d2f8dd03cdfb6be2bf1 Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Mon, 21 Oct 2024 13:11:42 -0700 Subject: [PATCH 1/3] moved away from using BinaryStreamUtils writing bitmap --- .../com/clickhouse/client/api/Client.java | 21 ++++---- .../internal/SerializerUtils.java | 49 ++++++++++++++++--- .../api/internal/HttpAPIClientHelper.java | 8 +-- 3 files changed, 53 insertions(+), 25 deletions(-) rename client-v2/src/main/java/com/clickhouse/client/api/{ => data_formats}/internal/SerializerUtils.java (92%) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/Client.java b/client-v2/src/main/java/com/clickhouse/client/api/Client.java index f68ae03df..200a898c9 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/Client.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/Client.java @@ -14,6 +14,7 @@ import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader; import com.clickhouse.client.api.data_formats.internal.MapBackedRecord; import com.clickhouse.client.api.data_formats.internal.ProcessParser; +import com.clickhouse.client.api.data_formats.internal.SerializerUtils; import com.clickhouse.client.api.enums.Protocol; import com.clickhouse.client.api.enums.ProxyType; import com.clickhouse.client.api.insert.DataSerializationException; @@ -25,7 +26,6 @@ import com.clickhouse.client.api.internal.ClientV1AdaptorHelper; import com.clickhouse.client.api.internal.HttpAPIClientHelper; import com.clickhouse.client.api.internal.MapUtils; -import com.clickhouse.client.api.internal.SerializerUtils; import com.clickhouse.client.api.internal.SettingsConverter; import com.clickhouse.client.api.internal.TableSchemaParser; import com.clickhouse.client.api.internal.ValidationUtils; @@ -46,7 +46,6 @@ import com.clickhouse.data.ClickHouseColumn; import com.clickhouse.data.ClickHouseDataType; import com.clickhouse.data.ClickHouseFormat; -import com.clickhouse.data.format.BinaryStreamUtils; import org.apache.hc.client5.http.ConnectTimeoutException; import org.apache.hc.core5.concurrent.DefaultThreadFactory; import org.apache.hc.core5.http.ClassicHttpResponse; @@ -1091,21 +1090,21 @@ public synchronized void register(Class clazz, TableSchema schema) { if (defaultsSupport) { if (value != null) {//Because we now support defaults, we have to send nonNull - BinaryStreamUtils.writeNonNull(stream);//Write 0 for no default + SerializerUtils.writeNonNull(stream);//Write 0 for no default if (column.isNullable()) {//If the column is nullable - BinaryStreamUtils.writeNonNull(stream);//Write 0 for not null + SerializerUtils.writeNonNull(stream);//Write 0 for not null } } else {//So if the object is null if (column.hasDefault()) { - BinaryStreamUtils.writeNull(stream);//Send 1 for default + SerializerUtils.writeNull(stream);//Send 1 for default return; } else if (column.isNullable()) {//And the column is nullable - BinaryStreamUtils.writeNonNull(stream); - BinaryStreamUtils.writeNull(stream);//Then we send null, write 1 + SerializerUtils.writeNonNull(stream); + SerializerUtils.writeNull(stream);//Then we send null, write 1 return;//And we're done } else if (column.getDataType() == ClickHouseDataType.Array) {//If the column is an array - BinaryStreamUtils.writeNonNull(stream);//Then we send nonNull + SerializerUtils.writeNonNull(stream);//Then we send nonNull } else { throw new IllegalArgumentException(String.format("An attempt to write null into not nullable column '%s'", column.getColumnName())); } @@ -1113,13 +1112,13 @@ public synchronized void register(Class clazz, TableSchema schema) { } else { if (column.isNullable()) { if (value == null) { - BinaryStreamUtils.writeNull(stream); + SerializerUtils.writeNull(stream); return; } - BinaryStreamUtils.writeNonNull(stream); + SerializerUtils.writeNonNull(stream); } else if (value == null) { if (column.getDataType() == ClickHouseDataType.Array) { - BinaryStreamUtils.writeNonNull(stream); + SerializerUtils.writeNonNull(stream); } else { throw new IllegalArgumentException(String.format("An attempt to write null into not nullable column '%s'", column.getColumnName())); } diff --git a/client-v2/src/main/java/com/clickhouse/client/api/internal/SerializerUtils.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/SerializerUtils.java similarity index 92% rename from client-v2/src/main/java/com/clickhouse/client/api/internal/SerializerUtils.java rename to client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/SerializerUtils.java index 56ab9eab3..022a8f75e 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/internal/SerializerUtils.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/SerializerUtils.java @@ -1,8 +1,7 @@ -package com.clickhouse.client.api.internal; +package com.clickhouse.client.api.data_formats.internal; import com.clickhouse.client.api.Client; import com.clickhouse.client.api.ClientException; -import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader; import com.clickhouse.client.api.query.POJOSetter; import com.clickhouse.data.ClickHouseAggregateFunction; import com.clickhouse.data.ClickHouseColumn; @@ -72,14 +71,14 @@ private static void serializeArrayData(OutputStream stream, Object value, ClickH //Serialize the array to the stream //The array is a list of values List values = (List) value; - BinaryStreamUtils.writeVarInt(stream, values.size()); + writeVarInt(stream, values.size()); for (Object val : values) { if (column.getArrayBaseColumn().isNullable()) { if (val == null) { - BinaryStreamUtils.writeNull(stream); + writeNull(stream); continue; } - BinaryStreamUtils.writeNonNull(stream); + writeNonNull(stream); } serializeData(stream, val, column.getArrayBaseColumn()); } @@ -107,7 +106,7 @@ private static void serializeMapData(OutputStream stream, Object value, ClickHou //Serialize the map to the stream //The map is a list of key-value pairs Map map = (Map) value; - BinaryStreamUtils.writeVarInt(stream, map.size()); + writeVarInt(stream, map.size()); map.forEach((key, val) -> { try { serializePrimitiveData(stream, key, Objects.requireNonNull(column.getKeyInfo())); @@ -213,7 +212,13 @@ private static void serializePrimitiveData(OutputStream stream, Object value, Cl private static void serializeAggregateFunction(OutputStream stream, Object value, ClickHouseColumn column) throws IOException { if (column.getAggregateFunction() == ClickHouseAggregateFunction.groupBitmap) { - BinaryStreamUtils.writeBitmap(stream, (ClickHouseBitmap) value); + if (value == null) { + throw new IllegalArgumentException("Cannot serialize null value for aggregate function: " + column.getAggregateFunction()); + } else if (value instanceof ClickHouseBitmap) { + stream.write(((ClickHouseBitmap)value).toBytes()); // TODO: review toBytes() implementation - it can be simplified + } else { + throw new IllegalArgumentException("Cannot serialize value of type " + value.getClass() + " for aggregate function: " + column.getAggregateFunction()); + } } else { throw new UnsupportedOperationException("Unsupported aggregate function: " + column.getAggregateFunction()); } @@ -527,4 +532,34 @@ public Class defineClass(String name, byte[] code) throws ClassNotFoundExcept return super.defineClass(name, code, 0, code.length); } } + + public static void writeVarInt(OutputStream output, long value) throws IOException { + // reference code https://github.com/ClickHouse/ClickHouse/blob/abe314feecd1647d7c2b952a25da7abf5c19f352/src/IO/VarInt.h#L187 + for (int i = 0; i < 9; i++) { + byte b = (byte) (value & 0x7F); + + if (value > 0x7F) { + b |= 0x80; + } + + output.write(b); + value >>= 7; + + if (value == 0) { + return; + } + } + } + + public static void writeNull(OutputStream output) throws IOException { + writeBoolean(output, true); + } + + public static void writeNonNull(OutputStream output) throws IOException { + writeBoolean(output, false); + } + + public static void writeBoolean(OutputStream output, boolean value) throws IOException { + output.write(value ? 1 : 0); + } } diff --git a/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java b/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java index 5a7f38cb9..9dd4176ea 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java @@ -10,6 +10,7 @@ import com.clickhouse.client.api.ConnectionInitiationException; import com.clickhouse.client.api.ConnectionReuseStrategy; import com.clickhouse.client.api.ServerException; +import com.clickhouse.client.api.data_formats.internal.SerializerUtils; import com.clickhouse.client.api.enums.ProxyType; import com.clickhouse.client.config.ClickHouseClientOption; import com.clickhouse.client.config.ClickHouseDefaults; @@ -54,11 +55,8 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLException; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; import java.net.ConnectException; import java.net.InetSocketAddress; @@ -66,15 +64,11 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; -import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.util.Base64; -import java.util.EnumSet; -import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.StringTokenizer; import java.util.concurrent.TimeUnit; import java.util.function.Function; From daedbda7dd71ac2d610eb838c708a069a1beddf0 Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Tue, 22 Oct 2024 13:07:37 -0700 Subject: [PATCH 2/3] fixed deserialization of ClickHouseBitmap --- .../data/value/ClickHouseBitmap.java | 2 +- .../ClickHouseBinaryFormatReader.java | 5 ++ .../internal/AbstractBinaryFormatReader.java | 11 ++++ .../internal/BinaryReaderBackedRecord.java | 11 ++++ .../internal/BinaryStreamReader.java | 7 ++- .../internal/MapBackedRecord.java | 11 ++++ .../client/api/query/GenericRecord.java | 5 ++ .../clickhouse/client/insert/SamplePOJO.java | 8 +-- .../client/query/AggregateFuncDTO.java | 54 +++++++++++++++++++ .../clickhouse/client/query/QueryTests.java | 32 +++++++++++ 10 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 client-v2/src/test/java/com/clickhouse/client/query/AggregateFuncDTO.java diff --git a/clickhouse-data/src/main/java/com/clickhouse/data/value/ClickHouseBitmap.java b/clickhouse-data/src/main/java/com/clickhouse/data/value/ClickHouseBitmap.java index e57247dec..20ded5b22 100644 --- a/clickhouse-data/src/main/java/com/clickhouse/data/value/ClickHouseBitmap.java +++ b/clickhouse-data/src/main/java/com/clickhouse/data/value/ClickHouseBitmap.java @@ -354,7 +354,7 @@ public static ClickHouseBitmap deserialize(DataInputStream in, ClickHouseDataTyp byte[] bytes = new byte[2 + byteLen * cardinality]; bytes[0] = (byte) flag; bytes[1] = cardinality; - in.read(bytes, 2, bytes.length - 2); + in.readFully(bytes, 2, bytes.length - 2); rb = ClickHouseBitmap.deserialize(bytes, innerType); } else { diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/ClickHouseBinaryFormatReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/ClickHouseBinaryFormatReader.java index 711499b81..da6ac3d36 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/ClickHouseBinaryFormatReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/ClickHouseBinaryFormatReader.java @@ -1,6 +1,7 @@ package com.clickhouse.client.api.data_formats; import com.clickhouse.client.api.metadata.TableSchema; +import com.clickhouse.data.value.ClickHouseBitmap; import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue; import com.clickhouse.data.value.ClickHouseGeoPointValue; import com.clickhouse.data.value.ClickHouseGeoPolygonValue; @@ -519,4 +520,8 @@ public interface ClickHouseBinaryFormatReader extends AutoCloseable { LocalDateTime getLocalDateTime(int index); TableSchema getSchema(); + + ClickHouseBitmap getClickHouseBitmap(String colName); + + ClickHouseBitmap getClickHouseBitmap(int index); } diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java index f30bdf95f..30bf17c42 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java @@ -8,6 +8,7 @@ import com.clickhouse.client.api.query.QuerySettings; import com.clickhouse.client.config.ClickHouseClientOption; import com.clickhouse.data.ClickHouseColumn; +import com.clickhouse.data.value.ClickHouseBitmap; import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue; import com.clickhouse.data.value.ClickHouseGeoPointValue; import com.clickhouse.data.value.ClickHouseGeoPolygonValue; @@ -661,6 +662,16 @@ public LocalDateTime getLocalDateTime(int index) { return (LocalDateTime) value; } + @Override + public ClickHouseBitmap getClickHouseBitmap(String colName) { + return readValue(colName); + } + + @Override + public ClickHouseBitmap getClickHouseBitmap(int index) { + return readValue(index); + } + @Override public void close() throws Exception { input.close(); diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryReaderBackedRecord.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryReaderBackedRecord.java index 9ee312154..7068d218e 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryReaderBackedRecord.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryReaderBackedRecord.java @@ -2,6 +2,7 @@ import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader; import com.clickhouse.client.api.query.GenericRecord; +import com.clickhouse.data.value.ClickHouseBitmap; import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue; import com.clickhouse.data.value.ClickHouseGeoPointValue; import com.clickhouse.data.value.ClickHouseGeoPolygonValue; @@ -356,4 +357,14 @@ public Object getObject(String colName) { public Object getObject(int index) { return reader.readValue(index); } + + @Override + public ClickHouseBitmap getClickHouseBitmap(String colName) { + return reader.readValue(colName); + } + + @Override + public ClickHouseBitmap getClickHouseBitmap(int index) { + return reader.readValue(index); + } } diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java index 7ef084ce1..5423b4093 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java @@ -216,7 +216,7 @@ public T readValue(ClickHouseColumn column, Class typeHint) throws IOExce return null; // case SimpleAggregateFunction: case AggregateFunction: - return (T) ClickHouseBitmap.deserialize(input, column.getNestedColumns().get(0).getDataType()); + return (T) readBitmap( column); default: throw new IllegalArgumentException("Unsupported data type: " + column.getDataType()); } @@ -885,6 +885,11 @@ public static boolean isReadToPrimitive(ClickHouseDataType dataType) { return false; } } + + private ClickHouseBitmap readBitmap(ClickHouseColumn column) throws IOException { + return ClickHouseBitmap.deserialize(input, column.getNestedColumns().get(0).getDataType()); + } + /** * Byte allocator that caches preallocated byte arrays for small sizes. */ diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/MapBackedRecord.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/MapBackedRecord.java index 57b92ac3f..8b0aa6bf0 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/MapBackedRecord.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/MapBackedRecord.java @@ -6,6 +6,7 @@ import com.clickhouse.client.api.query.NullValueException; import com.clickhouse.data.ClickHouseColumn; import com.clickhouse.data.value.ClickHouseArrayValue; +import com.clickhouse.data.value.ClickHouseBitmap; import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue; import com.clickhouse.data.value.ClickHouseGeoPointValue; import com.clickhouse.data.value.ClickHouseGeoPolygonValue; @@ -482,6 +483,16 @@ public LocalDateTime getLocalDateTime(int index) { return (LocalDateTime) value; } + @Override + public ClickHouseBitmap getClickHouseBitmap(String colName) { + return readValue(colName); + } + + @Override + public ClickHouseBitmap getClickHouseBitmap(int index) { + return readValue(index); + } + @Override public Object getObject(String colName) { return readValue(colName); diff --git a/client-v2/src/main/java/com/clickhouse/client/api/query/GenericRecord.java b/client-v2/src/main/java/com/clickhouse/client/api/query/GenericRecord.java index bc8f6e25e..1ff21e9aa 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/query/GenericRecord.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/query/GenericRecord.java @@ -1,5 +1,6 @@ package com.clickhouse.client.api.query; +import com.clickhouse.data.value.ClickHouseBitmap; import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue; import com.clickhouse.data.value.ClickHouseGeoPointValue; import com.clickhouse.data.value.ClickHouseGeoPolygonValue; @@ -489,4 +490,8 @@ public interface GenericRecord { Object getObject(String colName); Object getObject(int index); + + ClickHouseBitmap getClickHouseBitmap(String colName); + + ClickHouseBitmap getClickHouseBitmap(int index); } diff --git a/client-v2/src/test/java/com/clickhouse/client/insert/SamplePOJO.java b/client-v2/src/test/java/com/clickhouse/client/insert/SamplePOJO.java index 3590a294c..5b7a16833 100644 --- a/client-v2/src/test/java/com/clickhouse/client/insert/SamplePOJO.java +++ b/client-v2/src/test/java/com/clickhouse/client/insert/SamplePOJO.java @@ -680,10 +680,10 @@ public static String generateTableCreateSQL(String tableName) { "array Array(String), " + "tuple Tuple(UInt64, Int32, String), " + "map Map(String, Int32), " + - "nested Nested (innerInt Int32, innerString String, innerNullableInt Nullable(Int32))" + -// "groupBitmapUint32 AggregateFunction(groupBitmap, UInt32)," + - // TODO: fix this -// "groupBitmapUint64 AggregateFunction(groupBitmap, UInt64)" + + "nested Nested (innerInt Int32, innerString String, " + + "innerNullableInt Nullable(Int32)), " + + "groupBitmapUint32 AggregateFunction(groupBitmap, UInt32), " + + "groupBitmapUint64 AggregateFunction(groupBitmap, UInt64) " + ") ENGINE = Memory"; } } diff --git a/client-v2/src/test/java/com/clickhouse/client/query/AggregateFuncDTO.java b/client-v2/src/test/java/com/clickhouse/client/query/AggregateFuncDTO.java new file mode 100644 index 000000000..84ba5e4d1 --- /dev/null +++ b/client-v2/src/test/java/com/clickhouse/client/query/AggregateFuncDTO.java @@ -0,0 +1,54 @@ +package com.clickhouse.client.query; + +import com.clickhouse.data.value.ClickHouseBitmap; + +import java.util.Objects; +import java.util.Random; + +public class AggregateFuncDTO { + + private ClickHouseBitmap groupBitmapUint32; + private ClickHouseBitmap groupBitmapUint64; + + public AggregateFuncDTO() { + Random random = new Random(); + this.groupBitmapUint32 = ClickHouseBitmap.wrap(random.ints(5, Integer.MAX_VALUE - 100, Integer.MAX_VALUE).toArray()); + this.groupBitmapUint64 = ClickHouseBitmap.wrap(random.longs(5, Long.MAX_VALUE - 100, Long.MAX_VALUE).toArray()); + } + + public ClickHouseBitmap getGroupBitmapUint32() { + return groupBitmapUint32; + } + + public void setGroupBitmapUint32(ClickHouseBitmap groupBitmapUint32) { + this.groupBitmapUint32 = groupBitmapUint32; + } + + public ClickHouseBitmap getGroupBitmapUint64() { + return groupBitmapUint64; + } + + public void setGroupBitmapUint64(ClickHouseBitmap groupBitmapUint64) { + this.groupBitmapUint64 = groupBitmapUint64; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AggregateFuncDTO that = (AggregateFuncDTO) o; + return Objects.equals(groupBitmapUint32, that.groupBitmapUint32) && Objects.equals(groupBitmapUint64, that.groupBitmapUint64); + } + + @Override + public int hashCode() { + return Objects.hash(groupBitmapUint32, groupBitmapUint64); + } + + public static String generateTableCreateSQL(String tableName) { + return "CREATE TABLE " + tableName + " (" + + "groupBitmapUint32 AggregateFunction(groupBitmap, UInt32), " + + "groupBitmapUint64 AggregateFunction(groupBitmap, UInt64) " + + ") ENGINE = MergeTree() ORDER BY tuple()"; + } +} diff --git a/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java b/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java index e5711212e..cd44843c0 100644 --- a/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java @@ -16,6 +16,7 @@ import com.clickhouse.client.api.ServerException; import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader; import com.clickhouse.client.api.enums.Protocol; +import com.clickhouse.client.api.insert.InsertResponse; import com.clickhouse.client.api.insert.InsertSettings; import com.clickhouse.client.api.metadata.TableSchema; import com.clickhouse.client.api.metrics.ClientMetrics; @@ -26,6 +27,7 @@ import com.clickhouse.client.api.query.QueryResponse; import com.clickhouse.client.api.query.QuerySettings; import com.clickhouse.client.api.query.Records; +import com.clickhouse.client.insert.SamplePOJO; import com.clickhouse.data.ClickHouseDataType; import com.clickhouse.data.ClickHouseFormat; import com.fasterxml.jackson.databind.JsonNode; @@ -1618,6 +1620,36 @@ public static BigDecimal cropDecimal(BigDecimal value, int scale) { return new BigDecimal(bi, scale); } + @Test(groups = { "integration" }, enabled = true) + public void testReadingBitmap() throws Exception { + final String tableName = "bitmaps_test_table"; + final String createSQL = AggregateFuncDTO.generateTableCreateSQL(tableName); + final AggregateFuncDTO pojo = new AggregateFuncDTO(); + + try { + client.execute("DROP TABLE IF EXISTS " + tableName).get(); + client.execute(createSQL).get(); + } catch (Exception e) { + throw e; + } + + client.register(AggregateFuncDTO.class, client.getTableSchema(tableName, "default")); + + try (InsertResponse response = client.insert(tableName, Collections.singletonList(pojo)).get(30, TimeUnit.SECONDS)) { + Assert.assertEquals(response.getWrittenRows(), 1); + } + + try (QueryResponse queryResponse = + client.query("SELECT * FROM " + tableName + " LIMIT 1").get(30, TimeUnit.SECONDS)) { + + ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(queryResponse); + Assert.assertNotNull(reader.next()); + Assert.assertFalse(reader.hasNext()); + + Assert.assertEquals(reader.getClickHouseBitmap("groupBitmapUint32"), pojo.getGroupBitmapUint32()); + Assert.assertEquals(reader.getClickHouseBitmap("groupBitmapUint64"), pojo.getGroupBitmapUint64()); + } + } protected Client.Builder newClient() { ClickHouseNode node = getServer(ClickHouseProtocol.HTTP); From a0abab975a3e2c89078f31690961cd7c3dbcfb3d Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Tue, 29 Oct 2024 11:14:18 -0700 Subject: [PATCH 3/3] removed unused imports --- .../api/data_formats/internal/AbstractBinaryFormatReader.java | 1 - .../com/clickhouse/client/internal/SerializerUtilsTests.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java index e76b7fa2f..ce1f1d87f 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java @@ -2,7 +2,6 @@ import com.clickhouse.client.api.ClientException; import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader; -import com.clickhouse.client.api.internal.SerializerUtils; import com.clickhouse.client.api.metadata.TableSchema; import com.clickhouse.client.api.query.NullValueException; import com.clickhouse.client.api.query.POJOSetter; diff --git a/client-v2/src/test/java/com/clickhouse/client/internal/SerializerUtilsTests.java b/client-v2/src/test/java/com/clickhouse/client/internal/SerializerUtilsTests.java index f18dbd416..bf46f4d3e 100644 --- a/client-v2/src/test/java/com/clickhouse/client/internal/SerializerUtilsTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/internal/SerializerUtilsTests.java @@ -1,9 +1,9 @@ package com.clickhouse.client.internal; -import com.clickhouse.client.api.internal.SerializerUtils; +import com.clickhouse.client.api.data_formats.internal.SerializerUtils; import org.testng.annotations.Test; -import static org.testng.AssertJUnit.assertEquals; +import static org.junit.Assert.assertEquals; public class SerializerUtilsTests {