Skip to content

Commit

Permalink
Avoid handling JSON_ARRAY as multi value JSON during transformation (#…
Browse files Browse the repository at this point in the history
…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 289b433.

* handle empty JSON array during transformation

* cosmetic
  • Loading branch information
shounakmk219 authored Jan 2, 2025
1 parent b8fe601 commit 97cbbfc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -220,6 +222,22 @@ public void testJSON() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ public GenericRow transform(GenericRow record) {
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());
Expand Down

0 comments on commit 97cbbfc

Please sign in to comment.