use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestRecordBatchSizer method testEmptyVariableWidthVector.
/**
* Test to verify that record batch sizer handles the actual empty vectors correctly. RowSetBuilder by default
* allocates Drillbuf of 10bytes for each vector type which makes their capacity >0 and not ==0 which will be in
* case of empty vectors.
*/
@Test
public void testEmptyVariableWidthVector() {
final BatchSchema schema = new SchemaBuilder().add("key", MinorType.INT).add("value", MinorType.VARCHAR).build();
final RowSetBuilder builder = fixture.rowSetBuilder(schema);
final RowSet rows = builder.build();
// Release the initial bytes allocated by RowSetBuilder
VectorAccessibleUtilities.clear(rows.container());
try {
// Create RecordBatchSizer for this empty container and it should not fail
final RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
int totalDataSize = 0;
for (ColumnSize colSize : sizer.columns().values()) {
totalDataSize += colSize.getTotalDataSize();
}
// Verify that the totalDataSize for all the columns is zero
assertEquals(0, totalDataSize);
} catch (Exception ex) {
fail();
} finally {
rows.clear();
}
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestTupleSchema method testNestedSchema.
@Test
public void testNestedSchema() {
TupleMetadata schema = new SchemaBuilder().addList("list").addType(MinorType.BIGINT).addType(MinorType.VARCHAR).addMap().add("a", MinorType.INT).add("b", MinorType.VARCHAR).resumeUnion().addList().addType(MinorType.FLOAT8).addType(MinorType.DECIMAL18).buildNested().resumeSchema().buildSchema();
assertEquals(1, schema.size());
ColumnMetadata col = schema.metadata(0);
assertTrue(col.isVariant());
VariantMetadata union = col.variantSchema();
assertNotNull(union);
assertEquals(4, union.size());
assertTrue(union.hasType(MinorType.MAP));
assertTrue(union.hasType(MinorType.LIST));
ColumnMetadata mapCol = union.member(MinorType.MAP);
TupleMetadata mapSchema = mapCol.mapSchema();
assertEquals(2, mapSchema.size());
ColumnMetadata listCol = union.member(MinorType.LIST);
VariantMetadata listSchema = listCol.variantSchema();
assertEquals(2, listSchema.size());
assertTrue(listSchema.hasType(MinorType.FLOAT8));
assertTrue(listSchema.hasType(MinorType.DECIMAL18));
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestLoad method testSchemaChange.
@Test
public void testSchemaChange() throws SchemaChangeException {
final BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig);
final RecordBatchLoader batchLoader = new RecordBatchLoader(allocator);
// Initial schema: a: INT, b: VARCHAR
// Schema change: N/A
BatchSchema schema1 = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).build();
{
assertTrue(loadBatch(allocator, batchLoader, schema1));
assertTrue(schema1.isEquivalent(batchLoader.getSchema()));
batchLoader.getContainer().zeroVectors();
}
// Same schema
// Schema change: No
{
assertFalse(loadBatch(allocator, batchLoader, schema1));
assertTrue(schema1.isEquivalent(batchLoader.getSchema()));
batchLoader.getContainer().zeroVectors();
}
// Reverse columns: b: VARCHAR, a: INT
// Schema change: No
{
BatchSchema schema = new SchemaBuilder().add("b", MinorType.VARCHAR).add("a", MinorType.INT).build();
assertFalse(loadBatch(allocator, batchLoader, schema));
// Potential bug: see DRILL-5828
assertTrue(schema.isEquivalent(batchLoader.getSchema()));
batchLoader.getContainer().zeroVectors();
}
// Drop a column: a: INT
// Schema change: Yes
{
BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).build();
assertTrue(loadBatch(allocator, batchLoader, schema));
assertTrue(schema.isEquivalent(batchLoader.getSchema()));
batchLoader.getContainer().zeroVectors();
}
// Add a column: a: INT, b: VARCHAR, c: INT
// Schema change: Yes
{
assertTrue(loadBatch(allocator, batchLoader, schema1));
assertTrue(schema1.isEquivalent(batchLoader.getSchema()));
batchLoader.getContainer().zeroVectors();
BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).add("c", MinorType.INT).build();
assertTrue(loadBatch(allocator, batchLoader, schema));
assertTrue(schema.isEquivalent(batchLoader.getSchema()));
batchLoader.getContainer().zeroVectors();
}
// Change a column type: a: INT, b: VARCHAR, c: VARCHAR
// Schema change: Yes
{
BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).build();
assertTrue(loadBatch(allocator, batchLoader, schema));
assertTrue(schema.isEquivalent(batchLoader.getSchema()));
batchLoader.getContainer().zeroVectors();
}
// Empty schema
// Schema change: Yes
{
BatchSchema schema = new SchemaBuilder().build();
assertTrue(loadBatch(allocator, batchLoader, schema));
assertTrue(schema.isEquivalent(batchLoader.getSchema()));
batchLoader.getContainer().zeroVectors();
}
batchLoader.clear();
allocator.close();
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
the class TestMiniPlan method testUnionFilter.
@Test
public void testUnionFilter() throws Exception {
List<String> leftJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : 1 }]", "[{\"a\": 5, \"b\" : 5},{\"a\": 3, \"b\" : 8}]", "[{\"a\": 40, \"b\" : 3},{\"a\": 13, \"b\" : 100}]");
List<String> rightJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : 10 }]", "[{\"a\": 50, \"b\" : 100}]");
RecordBatch batch = new PopBuilder().physicalOperator(// Children list is provided through RecordBatch
new UnionAll(Collections.<PhysicalOperator>emptyList())).addInputAsChild().physicalOperator(new Filter(null, parseExpr("a=5"), 1.0f)).addJsonScanAsChild().jsonBatches(leftJsonBatches).columnsToRead("a", "b").buildAddAsInput().buildAddAsInput().addInputAsChild().physicalOperator(new Filter(null, parseExpr("a=50"), 1.0f)).addJsonScanAsChild().jsonBatches(rightJsonBatches).columnsToRead("a", "b").buildAddAsInput().buildAddAsInput().build();
BatchSchema expectedSchema = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).addNullable("b", TypeProtos.MinorType.BIGINT).withSVMode(BatchSchema.SelectionVectorMode.NONE).build();
new MiniPlanTestBuilder().root(batch).expectSchema(expectedSchema).baselineValues(5l, 1l).baselineValues(5l, 5l).baselineValues(50l, 100l).go();
}
use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.
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();
BatchSchema expectedSchema = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).build();
new MiniPlanTestBuilder().root(scanBatch).expectSchema(expectedSchema).baselineValues(100L).go();
}
Aggregations