Search in sources :

Example 36 with BatchSchemaBuilder

use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.

the class TestUnionDistinct method testUnionBothEmptyDirs.

@Test
public void testUnionBothEmptyDirs() throws Exception {
    SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("key", TypeProtos.MinorType.INT);
    final BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
    testBuilder().sqlQuery("SELECT key FROM dfs.tmp.`%1$s` UNION SELECT key FROM dfs.tmp.`%1$s`", EMPTY_DIR_NAME).schemaBaseLine(expectedSchema).build().run();
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test) SqlTest(org.apache.drill.categories.SqlTest)

Example 37 with BatchSchemaBuilder

use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.

the class TestUntypedNull method testCoalesceOnNotExistentColumnsWithGroupBy.

@Test
public void testCoalesceOnNotExistentColumnsWithGroupBy() throws Exception {
    String query = "select coalesce(unk1, unk2) as coal from cp.`tpch/nation.parquet` group by 1";
    SchemaBuilder schemaBuilder = new SchemaBuilder().add("coal", UNTYPED_NULL_TYPE);
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
    testBuilder().sqlQuery(query).schemaBaseLine(expectedSchema).go();
    testBuilder().sqlQuery(query).unOrdered().baselineColumns("coal").baselineValuesForSingleColumn(new Object[] { null }).go();
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) SqlFunctionTest(org.apache.drill.categories.SqlFunctionTest)

Example 38 with BatchSchemaBuilder

use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.

the class TestHashJoinAdvanced method testJoinLimit0Schema.

// DRILL-6606
@Test
public void testJoinLimit0Schema() throws Exception {
    String query = "SELECT l.l_quantity, l.l_shipdate, o.o_custkey\n" + "FROM (SELECT * FROM cp.`tpch/lineitem.parquet` LIMIT 0) l\n" + "    JOIN (SELECT * FROM cp.`tpch/orders.parquet` LIMIT 0) o \n" + "    ON l.l_orderkey = o.o_orderkey\n";
    final List<QueryDataBatch> dataBatches = client.runQuery(UserBitShared.QueryType.SQL, query);
    Assert.assertEquals(1, dataBatches.size());
    final QueryDataBatch queryDataBatch = dataBatches.get(0);
    final RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
    try {
        batchLoader.load(queryDataBatch.getHeader().getDef(), queryDataBatch.getData());
        final BatchSchema actualSchema = batchLoader.getSchema();
        SchemaBuilder schemaBuilder = new SchemaBuilder().add("l_quantity", TypeProtos.MinorType.FLOAT8, TypeProtos.DataMode.REQUIRED).add("l_shipdate", TypeProtos.MinorType.DATE, TypeProtos.DataMode.REQUIRED).add("o_custkey", TypeProtos.MinorType.INT, TypeProtos.DataMode.REQUIRED);
        final BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
        Assert.assertTrue(expectedSchema.isEquivalent(actualSchema));
    } finally {
        batchLoader.clear();
    }
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 39 with BatchSchemaBuilder

use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.

the class TestOperatorRecordBatch method mockBatch.

private static VectorContainer mockBatch() {
    SchemaBuilder schemaBuilder = new SchemaBuilder().add("a", MinorType.INT);
    VectorContainer container = new VectorContainer(fixture.allocator(), new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build());
    container.buildSchema(SelectionVectorMode.NONE);
    return container;
}
Also used : SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 40 with BatchSchemaBuilder

use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.

the class TestFileScanFramework method testEmptyProject.

@Test
public void testEmptyProject() {
    MockEarlySchemaReader reader = new MockEarlySchemaReader();
    reader.batchLimit = 1;
    // Select no columns
    FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
    builder.setProjection();
    builder.addReader(reader);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Expect data and implicit columns
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(new SchemaBuilder()).build();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow().addRow().build();
    // Schema should include implicit columns.
    assertTrue(scan.buildSchema());
    assertEquals(expectedSchema, scan.batchAccessor().schema());
    scan.batchAccessor().release();
    // Read one batch, should contain implicit columns
    assertTrue(scan.next());
    RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)58 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)58 BatchSchema (org.apache.drill.exec.record.BatchSchema)56 Test (org.junit.Test)56 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)20 RecordBatch (org.apache.drill.exec.record.RecordBatch)14 SubOperatorTest (org.apache.drill.test.SubOperatorTest)10 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)7 PlannerTest (org.apache.drill.categories.PlannerTest)5 SqlFunctionTest (org.apache.drill.categories.SqlFunctionTest)5 MaterializedField (org.apache.drill.exec.record.MaterializedField)5 SqlTest (org.apache.drill.categories.SqlTest)4 HashJoinPOP (org.apache.drill.exec.physical.config.HashJoinPOP)4 ScanFixture (org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)4 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)4 ClusterTest (org.apache.drill.test.ClusterTest)4 OperatorTest (org.apache.drill.categories.OperatorTest)3 ParquetTest (org.apache.drill.categories.ParquetTest)3 VectorTest (org.apache.drill.categories.VectorTest)3 ExecTest (org.apache.drill.exec.ExecTest)3