Search in sources :

Example 16 with BatchSchemaBuilder

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

the class TestNullInputMiniPlan method testUnionFilterAll.

@Test
public void testUnionFilterAll() throws Exception {
    List<String> leftJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : \"name1\" }]");
    List<String> rightJsonBatches = Lists.newArrayList("[{\"a\": 50, \"b\" : \"name2\" }]");
    RecordBatch leftScan = new JsonScanBuilder().jsonBatches(leftJsonBatches).columnsToRead("a", "b").build();
    RecordBatch leftFilter = new PopBuilder().physicalOperator(new Filter(null, parseExpr("a < 0"), 1.0f)).addInput(leftScan).build();
    RecordBatch rightScan = new JsonScanBuilder().jsonBatches(rightJsonBatches).columnsToRead("a", "b").build();
    RecordBatch rightFilter = new PopBuilder().physicalOperator(new Filter(null, parseExpr("a < 0"), 1.0f)).addInput(rightScan).build();
    RecordBatch batch = new PopBuilder().physicalOperator(// Children list is provided through RecordBatch
    new UnionAll(Collections.emptyList())).addInput(leftFilter).addInput(rightFilter).build();
    SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).addNullable("b", TypeProtos.MinorType.VARCHAR);
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).withSVMode(BatchSchema.SelectionVectorMode.NONE).build();
    new MiniPlanTestBuilder().root(batch).expectSchema(expectedSchema).expectZeroRow(true).go();
}
Also used : Filter(org.apache.drill.exec.physical.config.Filter) BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatch(org.apache.drill.exec.record.RecordBatch) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) UnionAll(org.apache.drill.exec.physical.config.UnionAll) Test(org.junit.Test)

Example 17 with BatchSchemaBuilder

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

the class TestNullInputMiniPlan method testOutputProjectEmpty.

@Test
public void testOutputProjectEmpty() throws Exception {
    final PhysicalOperator project = new Project(parseExprs("x", "col1", "x + 100", "col2", "100.0", "col3", "cast(nonExist as varchar(100))", "col4"), null, true);
    SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("col1", TypeProtos.MinorType.INT).addNullable("col2", TypeProtos.MinorType.INT).add("col3", TypeProtos.MinorType.FLOAT8).addNullable("col4", TypeProtos.MinorType.VARCHAR, 100);
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).withSVMode(BatchSchema.SelectionVectorMode.NONE).build();
    final RecordBatch input = createScanBatchFromJson(SINGLE_EMPTY_JSON);
    RecordBatch batch = new PopBuilder().physicalOperator(// Children list is provided through RecordBatch
    project).addInput(input).build();
    new MiniPlanTestBuilder().root(batch).expectSchema(expectedSchema).expectZeroRow(true).go();
}
Also used : Project(org.apache.drill.exec.physical.config.Project) BatchSchema(org.apache.drill.exec.record.BatchSchema) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) RecordBatch(org.apache.drill.exec.record.RecordBatch) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) Test(org.junit.Test)

Example 18 with BatchSchemaBuilder

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

the class TestNullInputMiniPlan method testJsonInputMixedWithEmptyFiles4.

/**
 * Test ScanBatch with mixed json files.
 * input is data_file, data_file, empty, empty
 */
@Test
public void testJsonInputMixedWithEmptyFiles4() throws Exception {
    RecordBatch scanBatch = createScanBatchFromJson(SINGLE_JSON, SINGLE_JSON2, SINGLE_EMPTY_JSON2, SINGLE_EMPTY_JSON2);
    SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("id", TypeProtos.MinorType.BIGINT).addNullable("name", TypeProtos.MinorType.VARCHAR);
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
    new MiniPlanTestBuilder().root(scanBatch).expectSchema(expectedSchema).baselineValues(100L, "John").baselineValues(1000L, "Joe").expectBatchNum(2).go();
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatch(org.apache.drill.exec.record.RecordBatch) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) Test(org.junit.Test)

Example 19 with BatchSchemaBuilder

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

the class TestNullInputMiniPlan method testUnionLeftEmtpy.

@Test
public void testUnionLeftEmtpy() throws Exception {
    // Children list is provided through RecordBatch
    final PhysicalOperator unionAll = new UnionAll(Collections.EMPTY_LIST);
    RecordBatch left = createScanBatchFromJson(SINGLE_EMPTY_JSON);
    String file = DrillFileUtils.getResourceAsFile("/tpchmulti/region/01.parquet").toURI().toString();
    List<Path> filePath = Collections.singletonList(new Path(file));
    RecordBatch scanBatch = new ParquetScanBuilder().fileSystem(fs).columnsToRead("R_REGIONKEY").inputPaths(filePath).build();
    RecordBatch projectBatch = new PopBuilder().physicalOperator(new Project(parseExprs("R_REGIONKEY+10", "regionkey"), null)).addInput(scanBatch).build();
    RecordBatch unionBatch = new PopBuilder().physicalOperator(unionAll).addInput(left).addInput(projectBatch).build();
    SchemaBuilder schemaBuilder = new SchemaBuilder().add("regionkey", TypeProtos.MinorType.BIGINT);
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
    new MiniPlanTestBuilder().root(unionBatch).expectSchema(expectedSchema).baselineValues(10L).baselineValues(11L).go();
}
Also used : Path(org.apache.hadoop.fs.Path) SchemaPath(org.apache.drill.common.expression.SchemaPath) RecordBatch(org.apache.drill.exec.record.RecordBatch) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) Project(org.apache.drill.exec.physical.config.Project) BatchSchema(org.apache.drill.exec.record.BatchSchema) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) UnionAll(org.apache.drill.exec.physical.config.UnionAll) Test(org.junit.Test)

Example 20 with BatchSchemaBuilder

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

the class TestMiniPlan method testSimpleJson.

@Test
public void testSimpleJson() throws Exception {
    List<String> jsonBatches = Lists.newArrayList("{\"a\":100}");
    RecordBatch scanBatch = new JsonScanBuilder().jsonBatches(jsonBatches).build();
    SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT);
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
    new MiniPlanTestBuilder().root(scanBatch).expectSchema(expectedSchema).baselineValues(100L).go();
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatch(org.apache.drill.exec.record.RecordBatch) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) Test(org.junit.Test) PlannerTest(org.apache.drill.categories.PlannerTest)

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