Skip to content
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

Avoid handling JSON_ARRAY as multi value JSON during transformation #14738

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
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
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
Loading