Search in sources :

Example 86 with TestBuilder

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

the class TestCorruptParquetDateCorrection method testQueryWithCorruptedDates.

// according to SQL spec. '4.4.3.5 Datetime types' year should be less than 9999
@Test(expected = UserRemoteException.class)
public void testQueryWithCorruptedDates() throws Exception {
    try {
        TestBuilder builder = testBuilder().sqlQuery("select * from table(dfs.`%s` (type => 'parquet', autoCorrectCorruptDates => false))", CORRUPTED_PARTITIONED_DATES_1_2_PATH).unOrdered().baselineColumns("date_col");
        addCorruptedDateBaselineValues(builder);
        builder.go();
        String query = "select * from table(dfs.`%s` (type => 'parquet', " + "autoCorrectCorruptDates => false)) where date_col = cast('15334-03-17' as date)";
        test(query, CORRUPTED_PARTITIONED_DATES_1_2_PATH);
    } catch (UserRemoteException e) {
        Assert.assertTrue(e.getMessage().contains("Year out of range"));
        throw e;
    } finally {
        resetAllSessionOptions();
    }
}
Also used : UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) TestBuilder(org.apache.drill.test.TestBuilder) ParquetTest(org.apache.drill.categories.ParquetTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 87 with TestBuilder

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

the class TestCorruptParquetDateCorrection method testReadOldMetadataCacheFile.

@Test
public void testReadOldMetadataCacheFile() throws Exception {
    // for sanity, try reading all partitions without a filter
    String query = format("select date_col from dfs.`%s`", PARTITIONED_1_2_FOLDER);
    TestBuilder builder = testBuilder().sqlQuery(query).unOrdered().baselineColumns("date_col");
    addDateBaselineValues(builder);
    builder.go();
    testPlanMatchingPatterns(query, new String[] { "usedMetadataFile=true" }, null);
}
Also used : TestBuilder(org.apache.drill.test.TestBuilder) ParquetTest(org.apache.drill.categories.ParquetTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 88 with TestBuilder

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

the class TestExternalSort method testNumericTypes.

/**
 * Test union type support in sort using numeric types: BIGINT and FLOAT8
 * Drill does not support union types fully. Sort was adapted to handle them.
 * This test simply verifies that the sort handles these types, even though
 * Drill does not.
 *
 * @throws Exception
 */
@Test
public void testNumericTypes() throws Exception {
    final int record_count = 10000;
    final String tableDirName = "numericTypes";
    {
        TupleMetadata schema = new SchemaBuilder().add("a", Types.required(TypeProtos.MinorType.INT)).buildSchema();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 0; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "a.json");
        new JsonFileBuilder(rowSet).prettyPrint(false).build(tableFile);
        rowSet.clear();
    }
    {
        final TupleMetadata schema = new SchemaBuilder().add("a", Types.required(TypeProtos.MinorType.FLOAT4)).buildSchema();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 1; i <= record_count; i += 2) {
            rowSetBuilder.addRow((float) i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "b.json");
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
    }
    TestBuilder builder = testBuilder().sqlQuery("select * from dfs.`%s` order by a desc", tableDirName).optionSettingQueriesForTestQuery("alter session set `exec.enable_union_type` = true").ordered().baselineColumns("a");
    for (int i = record_count; i >= 0; ) {
        builder.baselineValues((long) i--);
        if (i >= 0) {
            builder.baselineValues((double) i--);
        }
    }
    builder.go();
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) JsonFileBuilder(org.apache.drill.test.rowSet.file.JsonFileBuilder) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test) SlowTest(org.apache.drill.categories.SlowTest)

Example 89 with TestBuilder

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

the class TestExternalSort method testNumericAndStringTypes.

@Test
@Ignore("Schema changes are disabled in external sort")
public void testNumericAndStringTypes() throws Exception {
    final int record_count = 10000;
    final String tableDirName = "numericAndStringTypes";
    {
        final TupleMetadata schema = new SchemaBuilder().add("a", Types.required(TypeProtos.MinorType.INT)).buildSchema();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 0; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "a.json");
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
    }
    {
        final TupleMetadata schema = new SchemaBuilder().add("a", Types.required(TypeProtos.MinorType.INT)).buildSchema();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 1; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "b.json");
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
    }
    TestBuilder builder = testBuilder().sqlQuery("select * from dfs.`%s` order by a desc", tableDirName).ordered().optionSettingQueriesForTestQuery("alter session set `exec.enable_union_type` = true").baselineColumns("a");
    // Strings come first because order by is desc
    for (int i = record_count; i >= 0; ) {
        i--;
        if (i >= 0) {
            builder.baselineValues(String.format("%05d", i--));
        }
    }
    for (int i = record_count; i >= 0; ) {
        builder.baselineValues((long) i--);
        i--;
    }
    builder.go();
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) JsonFileBuilder(org.apache.drill.test.rowSet.file.JsonFileBuilder) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder) Ignore(org.junit.Ignore) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test) SlowTest(org.apache.drill.categories.SlowTest)

Example 90 with TestBuilder

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

the class TestExternalSort method testNewColumns.

@Test
public void testNewColumns() throws Exception {
    final int record_count = 10000;
    final String tableDirName = "newColumns";
    {
        final TupleMetadata schema = new SchemaBuilder().add("a", TypeProtos.MinorType.INT).add("b", TypeProtos.MinorType.INT).buildSchema();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 0; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i, i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "a.json");
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
    }
    {
        final TupleMetadata schema = new SchemaBuilder().add("a", TypeProtos.MinorType.INT).add("c", TypeProtos.MinorType.INT).buildSchema();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 1; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i, i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "b.json");
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
    }
    // Test framework currently doesn't handle changing schema (i.e. new
    // columns) on the client side
    TestBuilder builder = testBuilder().sqlQuery("select a, b, c from dfs.`%s` order by a desc", tableDirName).ordered().optionSettingQueriesForTestQuery("alter session set `exec.enable_union_type` = true").baselineColumns("a", "b", "c");
    for (int i = record_count; i >= 0; ) {
        builder.baselineValues((long) i, (long) i--, null);
        if (i >= 0) {
            builder.baselineValues((long) i, null, (long) i--);
        }
    }
    builder.go();
    // TODO: Useless test: just dumps to console
    test("select * from dfs.`%s` order by a desc", tableDirName);
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) JsonFileBuilder(org.apache.drill.test.rowSet.file.JsonFileBuilder) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test) SlowTest(org.apache.drill.categories.SlowTest)

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