Search in sources :

Example 11 with JsonStringHashMap

use of org.apache.drill.exec.util.JsonStringHashMap in project drill by axbaretto.

the class TestFlatten method testFlatten_Drill2162_complex.

@Test
@Category(UnlikelyTest.class)
public void testFlatten_Drill2162_complex() throws Exception {
    String jsonRecords = BaseTestQuery.getFile("flatten/complex_transaction_example_data.json");
    int numCopies = 700;
    new TestConstantFolding.SmallFileCreator(pathDir).setRecord(jsonRecords).createFiles(1, numCopies, "json");
    @SuppressWarnings("unchecked") List<JsonStringHashMap<String, Object>> data = Lists.newArrayList(mapOf("uid", 1l, "lst_lst_0", listOf(1l, 2l, 3l, 4l, 5l), "lst_lst_1", listOf(2l, 3l, 4l, 5l, 6l), "lst_lst", listOf(listOf(1l, 2l, 3l, 4l, 5l), listOf(2l, 3l, 4l, 5l, 6l))), mapOf("uid", 2l, "lst_lst_0", listOf(1l, 2l, 3l, 4l, 5l), "lst_lst_1", listOf(2l, 3l, 4l, 5l, 6l), "lst_lst", listOf(listOf(1l, 2l, 3l, 4l, 5l), listOf(2l, 3l, 4l, 5l, 6l))));
    List<JsonStringHashMap<String, Object>> result = flatten(flatten(flatten(data, "lst_lst_1"), "lst_lst_0"), "lst_lst");
    TestBuilder builder = testBuilder().sqlQuery("select uid, flatten(d.lst_lst[1]) lst1, flatten(d.lst_lst[0]) lst0, flatten(d.lst_lst) lst from " + "dfs.`%s/bigfile/bigfile.json` d", TEST_DIR).unOrdered().baselineColumns("uid", "lst1", "lst0", "lst");
    for (int i = 0; i < numCopies; i++) {
        for (JsonStringHashMap<String, Object> record : result) {
            builder.baselineValues(record.get("uid"), record.get("lst_lst_1"), record.get("lst_lst_0"), record.get("lst_lst"));
        }
    }
    builder.go();
}
Also used : JsonStringHashMap(org.apache.drill.exec.util.JsonStringHashMap) TestBuilder(org.apache.drill.test.TestBuilder) Category(org.junit.experimental.categories.Category) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 12 with JsonStringHashMap

use of org.apache.drill.exec.util.JsonStringHashMap in project drill by axbaretto.

the class TestBuilder method mapOf.

/**
 * Convenience method to create a {@link JsonStringHashMap<String, Object> map} instance with the given key value sequence.
 *
 * Key value sequence consists of key - value pairs such that a key precedes its value. For instance:
 *
 * mapOf("name", "Adam", "age", 41) corresponds to {"name": "Adam", "age": 41} in JSON.
 */
public static JsonStringHashMap<String, Object> mapOf(Object... keyValueSequence) {
    Preconditions.checkArgument(keyValueSequence.length % 2 == 0, "Length of key value sequence must be even");
    final JsonStringHashMap<String, Object> map = new JsonStringHashMap<>();
    for (int i = 0; i < keyValueSequence.length; i += 2) {
        Object value = keyValueSequence[i + 1];
        if (value instanceof CharSequence) {
            value = new Text(value.toString());
        }
        map.put(String.class.cast(keyValueSequence[i]), value);
    }
    return map;
}
Also used : Text(org.apache.drill.exec.util.Text) JsonStringHashMap(org.apache.drill.exec.util.JsonStringHashMap)

Example 13 with JsonStringHashMap

use of org.apache.drill.exec.util.JsonStringHashMap in project drill by apache.

the class AvroFormatTest method testLinkedList.

@Test
public void testLinkedList() throws Exception {
    int numRows = 5;
    String file = dataGenerator.generateLinkedList(numRows);
    TestBuilder testBuilder = testBuilder().sqlQuery("select * from dfs.`%s` t", file).unOrdered().baselineColumns("value", "next");
    for (long i = 0; i < numRows; i++) {
        if (i == numRows - 1) {
            // last row
            testBuilder.baselineValues(i, mapOf("next", new JsonStringHashMap<>()));
            continue;
        }
        testBuilder.baselineValues(i, mapOf("value", i + 1, "next", new JsonStringHashMap<>()));
    }
    testBuilder.go();
}
Also used : JsonStringHashMap(org.apache.drill.exec.util.JsonStringHashMap) TestBuilder(org.apache.drill.test.TestBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 14 with JsonStringHashMap

use of org.apache.drill.exec.util.JsonStringHashMap in project drill by apache.

the class TestBuilder method mapOf.

/**
 * Convenience method to create a {@link JsonStringHashMap<String, Object>} map instance with the given key value sequence.
 *
 * Key value sequence consists of key - value pairs such that a key precedes its value. For instance:
 *
 * mapOf("name", "Adam", "age", 41) corresponds to {"name": "Adam", "age": 41} in JSON.
 */
public static JsonStringHashMap<String, Object> mapOf(Object... keyValueSequence) {
    Preconditions.checkArgument(keyValueSequence.length % 2 == 0, "Length of key value sequence must be even");
    final JsonStringHashMap<String, Object> map = new JsonStringHashMap<>();
    for (int i = 0; i < keyValueSequence.length; i += 2) {
        Object value = keyValueSequence[i + 1];
        if (value instanceof CharSequence) {
            value = new Text(value.toString());
        }
        map.put(String.class.cast(keyValueSequence[i]), value);
    }
    return map;
}
Also used : Text(org.apache.drill.exec.util.Text) JsonStringHashMap(org.apache.drill.exec.util.JsonStringHashMap)

Example 15 with JsonStringHashMap

use of org.apache.drill.exec.util.JsonStringHashMap in project drill by apache.

the class TestFlatten method testFlatten_Drill2162_simple.

@Test
public void testFlatten_Drill2162_simple() throws Exception {
    List<Long> inputList = Lists.newArrayList();
    String jsonRecord = "{ \"int_list\" : [";
    final int listSize = 30;
    for (int i = 1; i < listSize; i++) {
        jsonRecord += i + ", ";
        inputList.add((long) i);
    }
    jsonRecord += listSize + "] }";
    inputList.add((long) listSize);
    int numRecords = 3000;
    new TestConstantFolding.SmallFileCreator(pathDir).setRecord(jsonRecord).createFiles(1, numRecords, "json");
    List<JsonStringHashMap<String, Object>> data = Lists.newArrayList(mapOf("int_list", inputList));
    List<JsonStringHashMap<String, Object>> result = flatten(data, "int_list");
    TestBuilder builder = testBuilder().sqlQuery("select flatten(int_list) as int_list from dfs.`%s/bigfile/bigfile.json`", TEST_DIR).unOrdered().baselineColumns("int_list");
    for (int i = 0; i < numRecords; i++) {
        for (JsonStringHashMap<String, Object> record : result) {
            builder.baselineValues(record.get("int_list"));
        }
    }
    builder.go();
}
Also used : JsonStringHashMap(org.apache.drill.exec.util.JsonStringHashMap) TestBuilder(org.apache.drill.test.TestBuilder) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Aggregations

JsonStringHashMap (org.apache.drill.exec.util.JsonStringHashMap)19 Text (org.apache.drill.exec.util.Text)14 Test (org.junit.Test)14 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)6 FlattenPOP (org.apache.drill.exec.physical.config.FlattenPOP)6 TestBuilder (org.apache.drill.test.TestBuilder)5 OperatorTest (org.apache.drill.categories.OperatorTest)4 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)4 LegacyOperatorTestBuilder (org.apache.drill.test.LegacyOperatorTestBuilder)3 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 JsonStringArrayList (org.apache.drill.exec.util.JsonStringArrayList)2 ClusterTest (org.apache.drill.test.ClusterTest)2 Category (org.junit.experimental.categories.Category)2 ArrayList (java.util.ArrayList)1 TestBuilder.mapOfObject (org.apache.drill.test.TestBuilder.mapOfObject)1 Snapshot (org.apache.iceberg.Snapshot)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1