Search in sources :

Example 26 with TestBuilder

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

the class TestMergeJoinWithSchemaChanges method testMissingAndNewColumns.

// DRILL-5612
@Test
public void testMissingAndNewColumns() throws Exception {
    // missing column kl
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(leftDir, "l1.json")));
    for (int i = 0; i < 50; ++i) {
        writer.write(String.format("{ \"kl1\" : %d , \"vl1\": %d }\n", i, i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(leftDir, "l2.json")));
    for (int i = 50; i < 100; ++i) {
        writer.write(String.format("{ \"kl\" : %d , \"vl\": %d }\n", i, i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(leftDir, "l3.json")));
    for (int i = 100; i < 150; ++i) {
        writer.write(String.format("{ \"kl2\" : %d , \"vl2\": %d }\n", i, i));
    }
    writer.close();
    // right missing column kr
    writer = new BufferedWriter(new FileWriter(new File(rightDir, "r1.json")));
    for (int i = 0; i < 50; ++i) {
        writer.write(String.format("{ \"kr1\" : %f , \"vr1\": %f }\n", (float) i, (float) i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(rightDir, "r2.json")));
    for (int i = 50; i < 100; ++i) {
        writer.write(String.format("{ \"kr\" : %f , \"vr\": %f }\n", (float) i, (float) i));
    }
    writer.close();
    writer = new BufferedWriter(new FileWriter(new File(rightDir, "r3.json")));
    for (int i = 100; i < 150; ++i) {
        writer.write(String.format("{ \"kr2\" : %f , \"vr2\": %f }\n", (float) i, (float) 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", "kl1", "vl1", "kl2", "vl2", "kr1", "vr1", "kr2", "vr2");
    for (long i = 50; i < 100; ++i) {
        builder.baselineValues(i, i, (double) i, (double) i, null, null, null, null, null, null, null, null);
    }
    builder.go();
    // LEFT JOIN
    query = String.format("select * from dfs.`%s` L %s join dfs.`%s` R on L.kl=R.kr", LEFT_DIR, "left", 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", "kl1", "vl1", "kl2", "vl2", "kr1", "vr1", "kr2", "vr2");
    for (long i = 0; i < 50; ++i) {
        builder.baselineValues(null, null, null, null, i, i, null, null, null, null, null, null);
    }
    for (long i = 50; i < 100; ++i) {
        builder.baselineValues(i, i, (double) i, (double) i, null, null, null, null, null, null, null, null);
    }
    for (long i = 100; i < 150; ++i) {
        builder.baselineValues(null, null, null, null, null, null, i, i, null, null, null, null);
    }
    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", "kl1", "vl1", "kl2", "vl2", "kr1", "vr1", "kr2", "vr2");
    for (long i = 0; i < 50; ++i) {
        builder.baselineValues(null, null, null, null, null, null, null, null, (double) i, (double) i, null, null);
    }
    for (long i = 50; i < 100; ++i) {
        builder.baselineValues(i, i, (double) i, (double) i, null, null, null, null, null, null, null, null);
    }
    for (long i = 100; i < 150; ++i) {
        builder.baselineValues(null, null, null, null, null, null, null, null, null, null, (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 27 with TestBuilder

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

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 28 with TestBuilder

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

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 29 with TestBuilder

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

the class TestLocalExchange method testHelper.

private static void testHelper(boolean isMuxOn, boolean isDeMuxOn, String query, int expectedNumMuxes, int expectedNumDeMuxes, String[] baselineColumns, List<Object[]> baselineValues) throws Exception {
    setupHelper(isMuxOn, isDeMuxOn);
    String plan = getPlanInString("EXPLAIN PLAN FOR " + query, JSON_FORMAT);
    if (isMuxOn) {
        // # of hash exchanges should be = # of mux exchanges + # of demux exchanges
        assertEquals("HashExpr on the hash column should not happen", 2 * expectedNumMuxes + expectedNumDeMuxes, StringUtils.countMatches(plan, HASH_EXPR_NAME));
        jsonExchangeOrderChecker(plan, isDeMuxOn, expectedNumMuxes, "hash32asdouble\\(.*\\) ");
    } else {
        assertEquals("HashExpr on the hash column should not happen", 0, StringUtils.countMatches(plan, HASH_EXPR_NAME));
    }
    // Make sure the plan has mux and demux exchanges (TODO: currently testing is rudimentary,
    // need to move it to sophisticated testing once we have better planning test tools are available)
    assertEquals("Wrong number of MuxExchanges are present in the plan", expectedNumMuxes, StringUtils.countMatches(plan, MUX_EXCHANGE));
    assertEquals("Wrong number of DeMuxExchanges are present in the plan", expectedNumDeMuxes, StringUtils.countMatches(plan, DEMUX_EXCHANGE));
    // Run the query and verify the output
    TestBuilder testBuilder = testBuilder().sqlQuery(query).unOrdered().baselineColumns(baselineColumns);
    for (Object[] baselineRecord : baselineValues) {
        testBuilder.baselineValues(baselineRecord);
    }
    testBuilder.go();
    testHelperVerifyPartitionSenderParallelization(plan, isMuxOn, isDeMuxOn);
}
Also used : JSONObject(org.json.simple.JSONObject) TestBuilder(org.apache.drill.test.TestBuilder)

Example 30 with TestBuilder

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

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("2", "2");
    builder.baselineValues(3l, 3l);
    builder.baselineValues(4.0d, 4.0d);
    builder.baselineValues("5", "5");
    builder.baselineValues(6l, 6l);
    builder.baselineValues(7.0d, 7.0d);
    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