Skip to content

Commit

Permalink
Revert "Bug fix: Complex type transformer should not be created for e…
Browse files Browse the repository at this point in the history
…mpty config (apache#8600)" (apache#8646)

This reverts commit 6484742.
  • Loading branch information
KKcorps authored May 5, 2022
1 parent 2896b1a commit 74ee725
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ private static String parseDelimiter(TableConfig tableConfig) {
*/
@Nullable
public static ComplexTypeTransformer getComplexTypeTransformer(TableConfig tableConfig) {
if (tableConfig.getIngestionConfig() != null && tableConfig.getIngestionConfig().getComplexTypeConfig() != null
&& tableConfig.getIngestionConfig().getComplexTypeConfig().getFieldsToUnnest() != null) {
if (tableConfig.getIngestionConfig() != null && tableConfig.getIngestionConfig().getComplexTypeConfig() != null) {
return new ComplexTypeTransformer(tableConfig);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.config.table.ingestion.ComplexTypeConfig;
import org.apache.pinot.spi.config.table.ingestion.IngestionConfig;
import org.apache.pinot.spi.data.readers.GenericRow;
import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -303,8 +298,8 @@ public void testConvertCollectionToString() {
// {
// "array":"[1,2]"
// }
transformer = new ComplexTypeTransformer(Arrays.asList(), ".", ComplexTypeConfig.CollectionNotUnnestedToJson.ALL,
new HashMap<>());
transformer = new ComplexTypeTransformer(Arrays.asList(), ".",
ComplexTypeConfig.CollectionNotUnnestedToJson.ALL, new HashMap<>());
genericRow = new GenericRow();
array = new Object[]{1, 2};
genericRow.putValue("array", array);
Expand Down Expand Up @@ -349,8 +344,8 @@ public void testConvertCollectionToString() {
array1[0] = ImmutableMap.of("b", "v1");
map.put("array1", array1);
genericRow.putValue("t", map);
transformer = new ComplexTypeTransformer(Arrays.asList(), ".", ComplexTypeConfig.CollectionNotUnnestedToJson.NONE,
new HashMap<>());
transformer = new ComplexTypeTransformer(Arrays.asList(), ".",
ComplexTypeConfig.CollectionNotUnnestedToJson.NONE, new HashMap<>());
transformer.transform(genericRow);
Assert.assertTrue(ComplexTypeTransformer.isArray(genericRow.getValue("t.array1")));
}
Expand All @@ -360,8 +355,8 @@ public void testRenamePrefixes() {
HashMap<String, String> prefixesToRename = new HashMap<>();
prefixesToRename.put("map1.", "");
prefixesToRename.put("map2", "test");
ComplexTypeTransformer transformer =
new ComplexTypeTransformer(new ArrayList<>(), ".", DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);
ComplexTypeTransformer transformer = new ComplexTypeTransformer(new ArrayList<>(), ".",
DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);

GenericRow genericRow = new GenericRow();
genericRow.putValue("a", 1L);
Expand All @@ -375,7 +370,8 @@ public void testRenamePrefixes() {
// name conflict where there becomes duplicate field names after renaming
prefixesToRename = new HashMap<>();
prefixesToRename.put("test.", "");
transformer = new ComplexTypeTransformer(new ArrayList<>(), ".", DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);
transformer = new ComplexTypeTransformer(new ArrayList<>(), ".",
DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);
genericRow = new GenericRow();
genericRow.putValue("a", 1L);
genericRow.putValue("test.a", 2L);
Expand All @@ -389,7 +385,8 @@ public void testRenamePrefixes() {
// name conflict where there becomes an empty field name after renaming
prefixesToRename = new HashMap<>();
prefixesToRename.put("test", "");
transformer = new ComplexTypeTransformer(new ArrayList<>(), ".", DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);
transformer = new ComplexTypeTransformer(new ArrayList<>(), ".",
DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);
genericRow = new GenericRow();
genericRow.putValue("a", 1L);
genericRow.putValue("test", 2L);
Expand All @@ -402,7 +399,8 @@ public void testRenamePrefixes() {

// case where nothing gets renamed
prefixesToRename = new HashMap<>();
transformer = new ComplexTypeTransformer(new ArrayList<>(), ".", DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);
transformer = new ComplexTypeTransformer(new ArrayList<>(), ".",
DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);
genericRow = new GenericRow();
genericRow.putValue("a", 1L);
genericRow.putValue("test", 2L);
Expand All @@ -416,8 +414,8 @@ public void testPrefixesToRename() {
HashMap<String, String> prefixesToRename = new HashMap<>();
prefixesToRename.put("map1.", "");
prefixesToRename.put("map2", "test");
ComplexTypeTransformer transformer =
new ComplexTypeTransformer(new ArrayList<>(), ".", DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);
ComplexTypeTransformer transformer = new ComplexTypeTransformer(new ArrayList<>(), ".",
DEFAULT_COLLECTION_TO_JSON_MODE, prefixesToRename);

// test flatten root-level tuples
GenericRow genericRow = new GenericRow();
Expand All @@ -440,26 +438,4 @@ public void testPrefixesToRename() {
Assert.assertEquals(genericRow.getValue("im1.bb"), "u");
Assert.assertEquals(genericRow.getValue("test.c"), 3);
}

@Test
public void getComplexTypeTransformerTest() {
ComplexTypeConfig complexTypeConfigWithNullFields = new ComplexTypeConfig(null, null, null, null);

IngestionConfig ingestionConfig = new IngestionConfig(null, null, null, null, complexTypeConfigWithNullFields);
TableConfig tableConfig =
new TableConfigBuilder(TableType.OFFLINE).setTableName("test_null").setIngestionConfig(ingestionConfig).build();

ComplexTypeTransformer complexTypeTransformer = ComplexTypeTransformer.getComplexTypeTransformer(tableConfig);
Assert.assertNull(complexTypeTransformer);

List<String> fieldToUnnest = Collections.singletonList("foo_bar");
ComplexTypeConfig complexTypeConfigWithNonNullField =
new ComplexTypeConfig(fieldToUnnest, null, null, null);
ingestionConfig = new IngestionConfig(null, null, null, null, complexTypeConfigWithNonNullField);
tableConfig =
new TableConfigBuilder(TableType.OFFLINE).setTableName("test_non_null").setIngestionConfig(ingestionConfig)
.build();
complexTypeTransformer = ComplexTypeTransformer.getComplexTypeTransformer(tableConfig);
Assert.assertNotNull(complexTypeTransformer);
}
}

0 comments on commit 74ee725

Please sign in to comment.