use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestNullInputMiniPlan method testJsonInputMixedWithEmptyFiles3.
/**
* Test ScanBatch with mixed json files.
* input is empty, data_file, data_file, empty
*/
@Test
public void testJsonInputMixedWithEmptyFiles3() throws Exception {
RecordBatch scanBatch = createScanBatchFromJson(SINGLE_EMPTY_JSON, SINGLE_JSON, SINGLE_JSON2, SINGLE_EMPTY_JSON2);
BatchSchema expectedSchema = new SchemaBuilder().addNullable("id", TypeProtos.MinorType.BIGINT).addNullable("name", TypeProtos.MinorType.VARCHAR).build();
new MiniPlanTestBuilder().root(scanBatch).expectSchema(expectedSchema).baselineValues(100L, "John").baselineValues(1000L, "Joe").expectBatchNum(2).go();
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
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.EMPTY_LIST)).addInput(leftFilter).addInput(rightFilter).build();
BatchSchema expectedSchema = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).addNullable("b", TypeProtos.MinorType.VARCHAR).withSVMode(BatchSchema.SelectionVectorMode.NONE).build();
new MiniPlanTestBuilder().root(batch).expectSchema(expectedSchema).expectZeroRow(true).go();
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestNullInputMiniPlan method testLeftHashJoinRightEmpty.
@Test
public void testLeftHashJoinRightEmpty() throws Exception {
List<String> leftJsonBatches = Lists.newArrayList("[{\"a\": 50, \"b\" : 10 }]");
RecordBatch leftScan = new JsonScanBuilder().jsonBatches(leftJsonBatches).columnsToRead("a", "b").build();
RecordBatch right = createScanBatchFromJson(SINGLE_EMPTY_JSON);
RecordBatch joinBatch = new PopBuilder().physicalOperator(new HashJoinPOP(null, null, Lists.newArrayList(joinCond("a", "EQUALS", "a2")), JoinRelType.LEFT)).addInput(leftScan).addInput(right).build();
BatchSchema expectedSchema = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).addNullable("b", TypeProtos.MinorType.BIGINT).withSVMode(BatchSchema.SelectionVectorMode.NONE).build();
new MiniPlanTestBuilder().root(joinBatch).expectSchema(expectedSchema).baselineValues(50L, 10L).go();
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestOperatorRecordBatch method mockBatch.
private static VectorContainer mockBatch() {
VectorContainer container = new VectorContainer(fixture.allocator(), new SchemaBuilder().add("a", MinorType.INT).build());
container.buildSchema(SelectionVectorMode.NONE);
return container;
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestOperatorRecordBatch method testSchemaChange.
@Test
public void testSchemaChange() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).build();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10, "fred").addRow(20, "wilma").build();
VectorContainer container = rs.container();
MockOperatorExec opExec = new MockOperatorExec(container);
int schemaVersion = opExec.batchAccessor().schemaVersion();
// Be tidy: start at 1.
assertEquals(1, schemaVersion);
// Changing data does not trigger schema change
container.zeroVectors();
opExec.batchAccessor.setContainer(container);
assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
// Different container, same vectors, does not trigger a change
VectorContainer c2 = new VectorContainer(fixture.allocator());
for (VectorWrapper<?> vw : container) {
c2.add(vw.getValueVector());
}
c2.buildSchema(SelectionVectorMode.NONE);
opExec.batchAccessor.setContainer(c2);
assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
opExec.batchAccessor.setContainer(container);
assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
// Replacing a vector with another of the same type does trigger
// a change.
VectorContainer c3 = new VectorContainer(fixture.allocator());
c3.add(container.getValueVector(0).getValueVector());
c3.add(TypeHelper.getNewVector(container.getValueVector(1).getValueVector().getField(), fixture.allocator(), null));
c3.buildSchema(SelectionVectorMode.NONE);
opExec.batchAccessor.setContainer(c3);
assertEquals(schemaVersion + 1, opExec.batchAccessor().schemaVersion());
schemaVersion = opExec.batchAccessor().schemaVersion();
// No change if same schema again
opExec.batchAccessor.setContainer(c3);
assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
// Adding a vector triggers a change
MaterializedField c = SchemaBuilder.columnSchema("c", MinorType.INT, DataMode.OPTIONAL);
c3.add(TypeHelper.getNewVector(c, fixture.allocator(), null));
c3.buildSchema(SelectionVectorMode.NONE);
opExec.batchAccessor.setContainer(c3);
assertEquals(schemaVersion + 1, opExec.batchAccessor().schemaVersion());
schemaVersion = opExec.batchAccessor().schemaVersion();
// No change if same schema again
opExec.batchAccessor.setContainer(c3);
assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
// Removing a vector triggers a change
c3.remove(c3.getValueVector(2).getValueVector());
c3.buildSchema(SelectionVectorMode.NONE);
assertEquals(2, c3.getNumberOfColumns());
opExec.batchAccessor.setContainer(c3);
assertEquals(schemaVersion + 1, opExec.batchAccessor().schemaVersion());
schemaVersion = opExec.batchAccessor().schemaVersion();
// Clean up
opExec.close();
c2.clear();
c3.clear();
}
Aggregations