Search in sources :

Example 16 with TestBuilder

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

the class TestMergeJoinWithSchemaChanges method testNumericTypes.

@Test
public void testNumericTypes() throws Exception {
    // First create data for numeric types.
    // left side int and float vs right side float
    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\" : %f , \"vl\": %f }\n", (float) i, (float) i));
    }
    writer.close();
    // right side is int and float
    writer = new BufferedWriter(new FileWriter(new File(rightDir, "r1.json")));
    for (int i = 2000; i < 7000; ++i) {
        writer.write(String.format("{ \"kr\" : %d , \"vr\": %d }\n", i, 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\" : %f, \"vr\": %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");
    for (long i = 2000; i < 3000; ++i) {
        builder.baselineValues(i, i, i, i);
        builder.baselineValues((double) i, (double) i, i, i);
    }
    for (long i = 3000; i < 5000; ++i) {
        builder.baselineValues(i, i, i, i);
        builder.baselineValues(i, i, (double) i, (double) i);
        builder.baselineValues((double) i, (double) i, i, i);
        builder.baselineValues((double) i, (double) i, (double) i, (double) i);
    }
    for (long i = 5000; i < 6000; ++i) {
        builder.baselineValues((double) i, (double) i, i, i);
        builder.baselineValues((double) i, (double) i, (double) i, (double) i);
    }
    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");
    for (long i = 0; i < 2000; ++i) {
        builder.baselineValues(i, i, null, null);
    }
    for (long i = 1000; i < 2000; ++i) {
        builder.baselineValues((double) i, (double) i, null, null);
    }
    for (long i = 2000; i < 3000; ++i) {
        builder.baselineValues(i, i, i, i);
        builder.baselineValues((double) i, (double) i, i, i);
    }
    for (long i = 3000; i < 5000; ++i) {
        builder.baselineValues(i, i, i, i);
        builder.baselineValues(i, i, (double) i, (double) i);
        builder.baselineValues((double) i, (double) i, i, i);
        builder.baselineValues((double) i, (double) i, (double) i, (double) i);
    }
    for (long i = 5000; i < 6000; ++i) {
        builder.baselineValues((double) i, (double) i, i, i);
        builder.baselineValues((double) i, (double) i, (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 17 with TestBuilder

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

the class TestBaseViewSupport method queryViewHelper.

/**
 * Execute the given query and check against the given baseline.
 *
 * @param query
 * @param baselineColumns
 * @param baselineValues
 * @throws Exception
 */
protected static void queryViewHelper(final String query, final String[] baselineColumns, final List<Object[]> baselineValues) throws Exception {
    TestBuilder testBuilder = testBuilder().sqlQuery(query).unOrdered().baselineColumns(baselineColumns);
    for (Object[] values : baselineValues) {
        testBuilder = testBuilder.baselineValues(values);
    }
    testBuilder.go();
}
Also used : TestBuilder(org.apache.drill.test.TestBuilder)

Example 18 with TestBuilder

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

the class AvroFormatTest method testDoubleNestedSchema_NoNullValues.

@Test
public void testDoubleNestedSchema_NoNullValues() throws Exception {
    final String file = generateDoubleNestedSchema_NoNullValues().getFileName();
    final String sql = "select a_string, b_int, t.c_record.nested_1_string, t.c_record.nested_1_int, " + "t.c_record.nested_1_record.double_nested_1_string, " + "t.c_record.nested_1_record.double_nested_1_int " + "from dfs.`%s` t";
    test(sql, file);
    final String sql2 = "select t.c_record.nested_1_string from dfs.`%s` t limit 1";
    TestBuilder testBuilder = testBuilder().sqlQuery(sql2, file).unOrdered().baselineColumns("EXPR$0");
    for (int i = 0; i < 1; i++) {
        testBuilder.baselineValues("nested_1_string_" + i);
    }
    testBuilder.go();
}
Also used : TestBuilder(org.apache.drill.test.TestBuilder) Test(org.junit.Test)

Example 19 with TestBuilder

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

the class AvroFormatTest method testFlattenPrimitiveArray.

// DRILL-4574"></a>
@Test
public void testFlattenPrimitiveArray() throws Exception {
    final String file = generateSimpleArraySchema_NoNullValues().getFileName();
    final String sql = "select a_string, flatten(c_string_array) as array_item from dfs.`%s` t";
    TestBuilder testBuilder = testBuilder().sqlQuery(sql, file).unOrdered().baselineColumns("a_string", "array_item");
    for (int i = 0; i < AvroTestUtil.RECORD_COUNT; i++) {
        for (int j = 0; j < AvroTestUtil.ARRAY_SIZE; j++) {
            testBuilder.baselineValues("a_" + i, "c_string_array_" + i + "_" + j);
        }
    }
    testBuilder.go();
}
Also used : TestBuilder(org.apache.drill.test.TestBuilder) Test(org.junit.Test)

Example 20 with TestBuilder

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

the class TestComplexTypeReader method test_array.

// DRILL-4410
@Test
public // ListVector allocation
void test_array() throws Exception {
    long numRecords = 100000;
    final String file1 = "arrays1.json";
    final String file2 = "arrays2.json";
    final Path path1 = dirTestWatcher.getRootDir().toPath().resolve(file1);
    final Path path2 = dirTestWatcher.getRootDir().toPath().resolve(file2);
    Files.createFile(path1);
    Files.createFile(path2);
    final String arrayString = "[ \"abcdef\", \"ghijkl\", \"mnopqr\", \"stuvwx\", \"yz1234\", \"567890\" ] ";
    try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(path1.toFile(), true)))) {
        for (long i = 0; i < numRecords; i++) {
            out.println("{ \"id\" : " + i + ", \"array\" : " + arrayString + "}");
        }
    } catch (IOException e) {
        throw e;
    }
    try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(path2.toFile(), true)))) {
        for (long i = 0; i < numRecords; i++) {
            out.println("{ \"id\" : " + i + ", \"array\" : " + arrayString + "}");
        }
    } catch (IOException e) {
        throw e;
    }
    TestBuilder testBuilder = testBuilder().sqlQuery("select * from dfs.`%s` `arrays1` INNER JOIN dfs.`%s` `arrays2` ON " + "(`arrays1`.id = `arrays2`.id)", file1, file2).unOrdered().baselineColumns("id", "id0", "array", "array0");
    for (long i = 0; i < numRecords; i++) {
        testBuilder.baselineValues(i, i, listOf("abcdef", "ghijkl", "mnopqr", "stuvwx", "yz1234", "567890"), listOf("abcdef", "ghijkl", "mnopqr", "stuvwx", "yz1234", "567890"));
    }
    testBuilder.go();
}
Also used : Path(java.nio.file.Path) FileWriter(java.io.FileWriter) IOException(java.io.IOException) TestBuilder(org.apache.drill.test.TestBuilder) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) 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