This is an automated email from the ASF dual-hosted git repository.
adarshsanjeev pushed a commit to branch datasketches-4.2.0
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/datasketches-4.2.0 by this
push:
new 35c2b35444b Add unit tests
35c2b35444b is described below
commit 35c2b35444b1c6b11549a5bd7d8481eb99fff59b
Author: Adarsh Sanjeev <[email protected]>
AuthorDate: Thu Oct 26 15:16:21 2023 +0530
Add unit tests
---
.../QuantilesSketchKeyCollectorFactory.java | 6 +-
.../druid/msq/statistics/ByteRowKeySerdeTest.java | 83 ++++++++++++++++++++++
2 files changed, 86 insertions(+), 3 deletions(-)
diff --git
a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/QuantilesSketchKeyCollectorFactory.java
b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/QuantilesSketchKeyCollectorFactory.java
index 925466bd743..674dfe15acb 100644
---
a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/QuantilesSketchKeyCollectorFactory.java
+++
b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/QuantilesSketchKeyCollectorFactory.java
@@ -93,9 +93,9 @@ public class QuantilesSketchKeyCollectorFactory
return new QuantilesSketchKeyCollector(comparator, sketch,
snapshot.getAverageKeyLength());
}
- private static class ByteRowKeySerde extends ArrayOfItemsSerDe<byte[]>
+ static class ByteRowKeySerde extends ArrayOfItemsSerDe<byte[]>
{
- private static final ByteRowKeySerde INSTANCE = new ByteRowKeySerde();
+ static final ByteRowKeySerde INSTANCE = new ByteRowKeySerde();
private ByteRowKeySerde()
{
@@ -173,7 +173,7 @@ public class QuantilesSketchKeyCollectorFactory
{
int length = Integer.BYTES * numItems;
for (int i = 0; i < numItems; i++) {
- length = mem.getInt(offsetBytes + (long) Integer.BYTES * i);
+ length += mem.getInt(offsetBytes + (long) Integer.BYTES * i);
}
return length;
}
diff --git
a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/statistics/ByteRowKeySerdeTest.java
b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/statistics/ByteRowKeySerdeTest.java
new file mode 100644
index 00000000000..9226ab4c81f
--- /dev/null
+++
b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/statistics/ByteRowKeySerdeTest.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.msq.statistics;
+
+import org.apache.datasketches.memory.Memory;
+import org.apache.druid.frame.key.KeyTestUtils;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.testing.InitializedNullHandlingTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ByteRowKeySerdeTest extends InitializedNullHandlingTest
+{
+ private final QuantilesSketchKeyCollectorFactory.ByteRowKeySerde serde =
+ QuantilesSketchKeyCollectorFactory.ByteRowKeySerde.INSTANCE;
+
+ @Test
+ public void testByteArraySerde()
+ {
+ testSerde(new byte[]{1, 5, 9, 3});
+ testSerde(new byte[][]{new byte[]{1, 5}, new byte[]{2, 3}, new byte[]{6,
7}});
+ }
+
+ @Test
+ public void testSerdeWithRowKeys()
+ {
+ RowSignature rowSignature = RowSignature.builder()
+ .add("x", ColumnType.LONG)
+ .add("y", ColumnType.LONG)
+ .build();
+
+ testSerde(KeyTestUtils.createKey(rowSignature, 2, 4).array());
+ }
+
+ @Test
+ public void testEmptyArray()
+ {
+ testSerde(new byte[][]{});
+ testSerde(new byte[][]{new byte[]{1, 5}, new byte[]{}, new byte[]{2, 3}});
+ }
+
+ private void testSerde(byte[] byteRowKey)
+ {
+ byte[] bytes = serde.serializeToByteArray(byteRowKey);
+ Assert.assertEquals(serde.sizeOf(byteRowKey), bytes.length);
+
+ Memory wrappedMemory = Memory.wrap(bytes);
+ Assert.assertEquals(serde.sizeOf(wrappedMemory, 0, 1), bytes.length);
+
+ byte[][] deserialized = serde.deserializeFromMemory(wrappedMemory, 1);
+ Assert.assertArrayEquals(new byte[][]{byteRowKey}, deserialized);
+ }
+
+ private void testSerde(byte[][] inputArray)
+ {
+ byte[] bytes = serde.serializeToByteArray(inputArray);
+ Assert.assertEquals(serde.sizeOf(inputArray), bytes.length);
+
+ Memory wrappedMemory = Memory.wrap(bytes);
+ Assert.assertEquals(serde.sizeOf(wrappedMemory, 0, inputArray.length),
bytes.length);
+
+ byte[][] deserialized = serde.deserializeFromMemory(wrappedMemory,
inputArray.length);
+ Assert.assertArrayEquals(inputArray, deserialized);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]