Search in sources :

Example 56 with TestBuilder

use of org.apache.drill.test.TestBuilder 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 57 with TestBuilder

use of org.apache.drill.test.TestBuilder in project drill by axbaretto.

the class TestMergeJoinWithSchemaChanges method testNumericStringTypes.

@Test
public void testNumericStringTypes() throws Exception {
    // left side int and strings
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(leftDir, "l1.json")));
    for (int i = 0; i < 5000; ++i) {
        writer.write(String.format("{ \"kl\" : %d , \"vl\": %d }\n", i, i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(leftDir, "l2.json")));
    for (int i = 1000; i < 6000; ++i) {
        writer.write(String.format("{ \"kl\" : \"%s\" , \"vl\": \"%s\" }\n", i, i));
    }
    writer.close();
    // right side is float and strings
    writer = new BufferedWriter(new FileWriter(new File(rightDir, "r1.json")));
    for (int i = 2000; i < 7000; ++i) {
        writer.write(String.format("{ \"kr\" : %f , \"vr\": %f }\n", (float) i, (float) i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(rightDir, "r2.json")));
    for (int i = 3000; i < 8000; ++i) {
        writer.write(String.format("{ \"kr\" : \"%s\", \"vr\": \"%s\" }\n", i, i));
    }
    writer.close();
    // INNER JOIN
    String query = String.format("select * from dfs.`%s` L %s join dfs.`%s` R on L.kl=R.kr", LEFT_DIR, "inner", RIGHT_DIR);
    TestBuilder builder = testBuilder().sqlQuery(query).optionSettingQueriesForTestQuery("alter session set `planner.enable_hashjoin` = false; alter session set `exec.enable_union_type` = true").unOrdered().baselineColumns("kl", "vl", "kr", "vr");
    for (long i = 2000; i < 5000; ++i) {
        builder.baselineValues(i, i, (double) i, (double) i);
    }
    for (long i = 3000; i < 6000; ++i) {
        final String d = Long.toString(i);
        builder.baselineValues(d, d, d, d);
    }
    builder.go();
    // RIGHT JOIN
    query = String.format("select * from dfs.`%s` L %s join dfs.`%s` R on L.kl=R.kr", LEFT_DIR, "right", RIGHT_DIR);
    builder = testBuilder().sqlQuery(query).optionSettingQueriesForTestQuery("alter session set `planner.enable_hashjoin` = false; alter session set `exec.enable_union_type` = true").unOrdered().baselineColumns("kl", "vl", "kr", "vr");
    for (long i = 2000; i < 5000; ++i) {
        builder.baselineValues(i, i, (double) i, (double) i);
    }
    for (long i = 3000; i < 6000; ++i) {
        final String d = Long.toString(i);
        builder.baselineValues(d, d, d, d);
    }
    for (long i = 5000; i < 7000; ++i) {
        builder.baselineValues(null, null, (double) i, (double) i);
    }
    for (long i = 6000; i < 8000; ++i) {
        final String d = Long.toString(i);
        builder.baselineValues(null, null, d, d);
    }
    builder.go();
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder) BufferedWriter(java.io.BufferedWriter) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 58 with TestBuilder

use of org.apache.drill.test.TestBuilder in project drill by axbaretto.

the class TestMergeJoinWithSchemaChanges method testOneSideSchemaChanges.

@Test
public void testOneSideSchemaChanges() throws Exception {
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(leftDir, "l1.json")));
    for (int i = 0; i < 50; ++i) {
        writer.write(String.format("{ \"kl\" : %d , \"vl\": %d }\n", i, i));
    }
    for (int i = 50; i < 100; ++i) {
        writer.write(String.format("{ \"kl\" : %f , \"vl\": %f }\n", (float) i, (float) i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(rightDir, "r1.json")));
    for (int i = 0; i < 50; ++i) {
        writer.write(String.format("{ \"kl\" : %d , \"vl\": %d }\n", i, i));
    }
    writer.close();
    String query = String.format("select * from dfs.`%s` L %s join dfs.`%s` R on L.kl=R.kl", LEFT_DIR, "inner", RIGHT_DIR);
    TestBuilder builder = testBuilder().sqlQuery(query).optionSettingQueriesForTestQuery("alter session set `planner.enable_hashjoin` = false; alter session set `exec.enable_union_type` = true").unOrdered().baselineColumns("kl", "vl", "kl0", "vl0");
    for (long i = 0; i < 50; ++i) {
        builder.baselineValues(i, i, i, i);
    }
    builder.go();
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder) BufferedWriter(java.io.BufferedWriter) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 59 with TestBuilder

use of org.apache.drill.test.TestBuilder in project drill by axbaretto.

the class TestTopNSchemaChanges method testUnionTypes.

@Test
public void testUnionTypes() throws Exception {
    // union of int and float and string.
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(tableDir, "d1.json")));
    for (int i = 0; i <= 9; ++i) {
        switch(i % 3) {
            case // 0, 3, 6, 9
            0:
                writer.write(String.format("{ \"kl\" : %d , \"vl\": %d }\n", i, i));
                break;
            case // 1, 4, 7
            1:
                writer.write(String.format("{ \"kl\" : %f , \"vl\": %f }\n", (float) i, (float) i));
                break;
            case // 2, 5, 8
            2:
                writer.write(String.format("{ \"kl\" : \"%s\" , \"vl\": \"%s\" }\n", i, i));
                break;
        }
    }
    writer.close();
    TestBuilder builder = testBuilder().sqlQuery("select * from dfs.`%s` order by kl limit 8", TABLE).optionSettingQueriesForTestQuery("alter session set `exec.enable_union_type` = true").ordered().baselineColumns("kl", "vl");
    builder.baselineValues(0l, 0l);
    builder.baselineValues(1.0d, 1.0d);
    builder.baselineValues(3l, 3l);
    builder.baselineValues(4.0d, 4.0d);
    builder.baselineValues(6l, 6l);
    builder.baselineValues(7.0d, 7.0d);
    builder.baselineValues(9l, 9l);
    builder.baselineValues("2", "2");
    builder.go();
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder) BufferedWriter(java.io.BufferedWriter) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 60 with TestBuilder

use of org.apache.drill.test.TestBuilder in project drill by axbaretto.

the class TestTopNSchemaChanges method testNumericAndStringTypes.

@Test
public void testNumericAndStringTypes() throws Exception {
    // left side int and strings
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(tableDir, "d1.json")));
    for (int i = 0; i < 1000; i += 2) {
        writer.write(String.format("{ \"kl\" : %d , \"vl\": %d }\n", i, i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(tableDir, "d2.json")));
    for (int i = 1; i < 1000; i += 2) {
        writer.write(String.format("{ \"kl\" : \"%s\" , \"vl\": \"%s\" }\n", i, i));
    }
    writer.close();
    TestBuilder builder = testBuilder().sqlQuery("select * from dfs.`%s` order by kl limit 12", TABLE).optionSettingQueriesForTestQuery("alter session set `exec.enable_union_type` = true").ordered().baselineColumns("kl", "vl");
    for (long i = 0; i < 24; i += 2) {
        builder.baselineValues(i, i);
    }
    builder = testBuilder().sqlQuery("select * from dfs.`%s` order by kl desc limit 12", TABLE).optionSettingQueriesForTestQuery("alter session set `exec.enable_union_type` = true").ordered().baselineColumns("kl", "vl").baselineValues("999", "999").baselineValues("997", "997").baselineValues("995", "995").baselineValues("993", "993").baselineValues("991", "991").baselineValues("99", "99").baselineValues("989", "989").baselineValues("987", "987").baselineValues("985", "985").baselineValues("983", "983").baselineValues("981", "981").baselineValues("979", "979");
    builder.go();
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder) BufferedWriter(java.io.BufferedWriter) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Aggregations

TestBuilder (org.apache.drill.test.TestBuilder)94 Test (org.junit.Test)74 File (java.io.File)27 OperatorTest (org.apache.drill.categories.OperatorTest)27 ClusterTest (org.apache.drill.test.ClusterTest)20 BufferedWriter (java.io.BufferedWriter)18 FileWriter (java.io.FileWriter)18 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)16 ParquetTest (org.apache.drill.categories.ParquetTest)10 TestBuilder.mapOfObject (org.apache.drill.test.TestBuilder.mapOfObject)6 Path (java.nio.file.Path)5 JsonFileBuilder (org.apache.drill.test.rowSet.file.JsonFileBuilder)5 Category (org.junit.experimental.categories.Category)5 SlowTest (org.apache.drill.categories.SlowTest)4 SqlTest (org.apache.drill.categories.SqlTest)4 JsonStringHashMap (org.apache.drill.exec.util.JsonStringHashMap)4 IOException (java.io.IOException)3 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)3 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)3 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)3