This is an automated email from the ASF dual-hosted git repository.
xiangfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 97cbbfce9e Avoid handling JSON_ARRAY as multi value JSON during
transformation (#14738)
97cbbfce9e is described below
commit 97cbbfce9ed822f98a2eee40a642710a5a990646
Author: Shounak kulkarni <[email protected]>
AuthorDate: Thu Jan 2 21:28:04 2025 +0530
Avoid handling JSON_ARRAY as multi value JSON during transformation (#14738)
* Avoid handling JSON_ARRAY as multi value JSON during transformation
* Revert "Avoid handling JSON_ARRAY as multi value JSON during
transformation"
This reverts commit 289b43340e852305e338ebf77a9fa5e83e63e298.
* handle empty JSON array during transformation
* cosmetic
---
.../apache/pinot/common/utils/PinotDataTypeTest.java | 18 ++++++++++++++++++
.../local/recordtransformer/DataTypeTransformer.java | 7 ++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git
a/pinot-common/src/test/java/org/apache/pinot/common/utils/PinotDataTypeTest.java
b/pinot-common/src/test/java/org/apache/pinot/common/utils/PinotDataTypeTest.java
index 245ea7235d..47807d674b 100644
---
a/pinot-common/src/test/java/org/apache/pinot/common/utils/PinotDataTypeTest.java
+++
b/pinot-common/src/test/java/org/apache/pinot/common/utils/PinotDataTypeTest.java
@@ -18,11 +18,13 @@
*/
package org.apache.pinot.common.utils;
+import com.fasterxml.jackson.core.JsonProcessingException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import org.apache.pinot.spi.utils.JsonUtils;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -220,6 +222,22 @@ public class PinotDataTypeTest {
assertEquals(JSON.convert(new Timestamp(1620324238610L), TIMESTAMP),
"1620324238610");
}
+ @Test
+ public void testJSONArray()
+ throws JsonProcessingException {
+ assertEquals(JSON.convert(new Object[]{false}, BOOLEAN), "[false]");
+ assertEquals(JSON.convert(new Object[]{true}, BOOLEAN), "[true]"); //
Base64 encoding.
+ assertEquals(JSON.convert(new Object[]{
+ JsonUtils.stringToObject("{\"bytes\":\"AAE=\"}", Map.class),
+
JsonUtils.stringToObject("{\"map\":{\"key1\":\"value\",\"key2\":null,\"array\":[-5.4,4,\"2\"]}}",
+ Map.class),
+ JsonUtils.stringToObject("{\"timestamp\":1620324238610}",
Map.class)}, JSON),
+
"[{\"bytes\":\"AAE=\"},{\"map\":{\"key1\":\"value\",\"key2\":null,\"array\":[-5.4,4,\"2\"]}},"
+ + "{\"timestamp\":1620324238610}]");
+ assertEquals(JSON.convert(new Object[]{}, JSON), "[]");
+ assertEquals(JSON.convert(new Object[]{new Timestamp(1620324238610L)},
TIMESTAMP), "[1620324238610]");
+ }
+
@Test
public void testObject() {
assertEquals(OBJECT.toInt(new NumberObject("123")), 123);
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/recordtransformer/DataTypeTransformer.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/recordtransformer/DataTypeTransformer.java
index 65019549ec..df1722b78f 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/recordtransformer/DataTypeTransformer.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/recordtransformer/DataTypeTransformer.java
@@ -94,7 +94,12 @@ public class DataTypeTransformer implements
RecordTransformer {
if (value instanceof Object[]) {
// Multi-value column
Object[] values = (Object[]) value;
- source = PinotDataType.getMultiValueType(values[0].getClass());
+ // JSON is not standardised for empty json array
+ if (dest == PinotDataType.JSON && values.length == 0) {
+ source = PinotDataType.JSON;
+ } else {
+ source = PinotDataType.getMultiValueType(values[0].getClass());
+ }
} else {
// Single-value column
source = PinotDataType.getSingleValueType(value.getClass());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]