Search in sources :

Example 31 with TestBuilder

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

the class TestTopNSchemaChanges method testNumericTypes.

@Test
public void testNumericTypes() throws Exception {
    // left side int and floats
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(tableDir, "d1.json")));
    for (int i = 0; i < 10000; 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 < 10000; i += 2) {
        writer.write(String.format("{ \"kl\": %f, \"vl\": %f }\n", (float) i, (float) 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 < 12; ++i) {
        if (i % 2 == 0) {
            builder.baselineValues(i, i);
        } else {
            builder.baselineValues((double) i, (double) 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 32 with TestBuilder

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

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)

Example 33 with TestBuilder

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

the class TestTopNSchemaChanges method testMissingColumn.

@Test
public void testMissingColumn() throws Exception {
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(tableDir, "d1.json")));
    for (int i = 0; i < 100; i++) {
        writer.write(String.format("{ \"kl1\": %d, \"vl1\": %d }\n", i, i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(tableDir, "d2.json")));
    for (int i = 100; i < 200; i++) {
        writer.write(String.format("{ \"kl\": %f, \"vl\": %f }\n", (float) i, (float) i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(tableDir, "d3.json")));
    for (int i = 200; i < 300; i++) {
        writer.write(String.format("{ \"kl2\": \"%s\", \"vl2\": \"%s\" }\n", i, i));
    }
    writer.close();
    TestBuilder builder = testBuilder().sqlQuery("select kl, vl, kl1, vl1, kl2, vl2 from dfs.`%s` order by kl limit 3", TABLE).optionSettingQueriesForTestQuery("alter session set `exec.enable_union_type` = true").ordered().baselineColumns("kl", "vl", "kl1", "vl1", "kl2", "vl2").baselineValues(100.0d, 100.0d, null, null, null, null).baselineValues(101.0d, 101.0d, null, null, null, null).baselineValues(102.0d, 102.0d, null, null, null, null);
    builder.go();
    builder = testBuilder().sqlQuery("select kl, vl, kl1, vl1, kl2, vl2  from dfs.`%s` order by kl1 limit 3", TABLE).optionSettingQueriesForTestQuery("alter session set `exec.enable_union_type` = true").ordered().baselineColumns("kl", "vl", "kl1", "vl1", "kl2", "vl2").baselineValues(null, null, 0l, 0l, null, null).baselineValues(null, null, 1l, 1l, null, null).baselineValues(null, null, 2l, 2l, null, null);
    builder.go();
    builder = testBuilder().sqlQuery("select kl, vl, kl1, vl1, kl2, vl2 from dfs.`%s` order by kl2 limit 3", TABLE).optionSettingQueriesForTestQuery("alter session set `exec.enable_union_type` = true").ordered().baselineColumns("kl", "vl", "kl1", "vl1", "kl2", "vl2").baselineValues(null, null, null, null, "200", "200").baselineValues(null, null, null, null, "201", "201").baselineValues(null, null, null, null, "202", "202");
    builder.go();
    // Since client can't handle new columns which are not in first batch, we won't test output of query.
    // Query should run w/o any errors.
    test("select * from dfs.`%s` order by kl limit 3", TABLE);
}
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 34 with TestBuilder

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

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");
    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 35 with TestBuilder

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

the class TestFlatten method drill1673.

// repeated list within a repeated map
@Test
@Category(UnlikelyTest.class)
public void drill1673() throws Exception {
    String jsonRecords = BaseTestQuery.getFile("store/json/1673.json");
    int numCopies = 25000;
    new TestConstantFolding.SmallFileCreator(pathDir).setRecord(jsonRecords).createFiles(1, numCopies, "json");
    TestBuilder builder = testBuilder().sqlQuery("select t.fixed_column as fixed_column, " + "flatten(t.list_column) as list_col " + "from dfs.`%s/bigfile/bigfile.json` as t", TEST_DIR).baselineColumns("fixed_column", "list_col").unOrdered();
    Object map1 = mapOf("id1", "1", "name", "zhu", "num", listOf(listOf(1l, 2l, 3l)));
    Object map2 = mapOf("id1", "2", "name", "hao", "num", listOf(listOf(4l, 5l, 6l)));
    for (int i = 0; i < numCopies; i++) {
        builder.baselineValues("abc", map1);
        builder.baselineValues("abc", map2);
    }
    builder.go();
}
Also used : 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)

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