Search in sources :

Example 1 with TestBuilder

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

the class BaseTestHiveImpersonation method showTablesHelper.

protected void showTablesHelper(final String db, List<String> expectedTables) throws Exception {
    final String dbQualified = hivePluginName + "." + db;
    final TestBuilder testBuilder = testBuilder().sqlQuery("SHOW TABLES IN " + dbQualified).unOrdered().baselineColumns("TABLE_SCHEMA", "TABLE_NAME");
    if (expectedTables.size() == 0) {
        testBuilder.expectsEmptyResultSet();
    } else {
        for (String tbl : expectedTables) {
            testBuilder.baselineValues(dbQualified, tbl);
        }
    }
    testBuilder.go();
}
Also used : TestBuilder(org.apache.drill.test.TestBuilder)

Example 2 with TestBuilder

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

the class BaseTestHiveImpersonation method fromInfoSchemaHelper.

protected void fromInfoSchemaHelper(final String pluginName, final String db, List<String> expectedTables, List<TableType> expectedTableTypes) throws Exception {
    final String dbQualified = pluginName + "." + db;
    final TestBuilder testBuilder = testBuilder().sqlQuery("SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE \n" + "FROM INFORMATION_SCHEMA.`TABLES` \n" + "WHERE TABLE_SCHEMA = '" + dbQualified + "'").unOrdered().baselineColumns("TABLE_SCHEMA", "TABLE_NAME", "TABLE_TYPE");
    if (expectedTables.size() == 0) {
        testBuilder.expectsEmptyResultSet();
    } else {
        for (int i = 0; i < expectedTables.size(); ++i) {
            testBuilder.baselineValues(dbQualified, expectedTables.get(i), expectedTableTypes.get(i).toString());
        }
    }
    testBuilder.go();
}
Also used : TestBuilder(org.apache.drill.test.TestBuilder)

Example 3 with TestBuilder

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

the class TestSelectWithOption method testWithResult.

private void testWithResult(String query, Object... expectedResult) throws Exception {
    TestBuilder builder = testBuilder().sqlQuery(query).ordered().baselineColumns("columns");
    for (Object o : expectedResult) {
        builder = builder.baselineValues(o);
    }
    builder.build().run();
}
Also used : TestBuilder(org.apache.drill.test.TestBuilder)

Example 4 with TestBuilder

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

the class TestTopNSchemaChanges method testNumericTypes.

@Test
public void testNumericTypes() throws Exception {
    // left side int and strings
    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 5 with TestBuilder

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

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)

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