use of org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder in project drill by apache.
the class TestRowBatchMerger method testMapRevision.
/**
* Test that the merger mechanism can rewrite a map to include
* projected null columns.
*/
@Test
public void testMapRevision() {
// Create the first batch
TupleMetadata inputSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).addMap("a").add("c", MinorType.INT).resumeSchema().buildSchema();
RowSetSource input = new RowSetSource(fixture.rowSetBuilder(inputSchema).addRow("barney", singleMap(10)).addRow("wilma", singleMap(20)).build());
// Create mappings
NullColumnBuilder builder = new NullBuilderBuilder().build();
ResolvedRow resolvedTuple = new ResolvedRow(builder);
resolvedTuple.add(new TestProjection(resolvedTuple, 0));
ResolvedMapColumn mapCol = new ResolvedMapColumn(resolvedTuple, inputSchema.column(1), 1);
resolvedTuple.add(mapCol);
ResolvedTuple map = mapCol.members();
map.add(new TestProjection(map, 0));
map.add(map.nullBuilder().add("null1"));
// Build the null values
ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
resolvedTuple.buildNulls(cache);
// LoadNulls
resolvedTuple.loadNulls(input.rowSet().rowCount());
// Do the merge
VectorContainer output = new VectorContainer(fixture.allocator());
resolvedTuple.project(input.rowSet().container(), output);
output.setRecordCount(input.rowSet().rowCount());
RowSet result = fixture.wrap(output);
// Verify
TupleMetadata expectedSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).addMap("a").add("c", MinorType.INT).addNullable("null1", MinorType.INT).resumeSchema().buildSchema();
RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow("barney", mapValue(10, null)).addRow("wilma", mapValue(20, null)).build();
new RowSetComparison(expected).verifyAndClearAll(result);
}
use of org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder in project drill by apache.
the class TestRowBatchMerger method testNullMaps.
/**
* Test the ability to create maps from whole cloth if requested in
* the projection list, and the map is not available from the data
* source.
*/
@Test
public void testNullMaps() {
// Create the first batch
RowSetSource first = makeFirst();
// Create null columns
NullColumnBuilder builder = new NullBuilderBuilder().build();
ResolvedRow resolvedTuple = new ResolvedRow(builder);
resolvedTuple.add(new TestProjection(resolvedTuple, 1));
ResolvedMapColumn nullMapCol = new ResolvedMapColumn(resolvedTuple, "map1");
ResolvedTuple nullMap = nullMapCol.members();
nullMap.add(nullMap.nullBuilder().add("null1"));
nullMap.add(nullMap.nullBuilder().add("null2", Types.optional(MinorType.VARCHAR)));
ResolvedMapColumn nullMapCol2 = new ResolvedMapColumn(nullMap, "map2");
ResolvedTuple nullMap2 = nullMapCol2.members();
nullMap2.add(nullMap2.nullBuilder().add("null3"));
nullMap.add(nullMapCol2);
resolvedTuple.add(nullMapCol);
resolvedTuple.add(new TestProjection(resolvedTuple, 0));
// Build the null values
ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
resolvedTuple.buildNulls(cache);
// LoadNulls
resolvedTuple.loadNulls(first.rowSet().rowCount());
// Do the merge
VectorContainer output = new VectorContainer(fixture.allocator());
resolvedTuple.project(first.rowSet().container(), output);
resolvedTuple.setRowCount(first.rowSet().rowCount());
RowSet result = fixture.wrap(output);
// Verify
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("map1").addNullable("null1", MinorType.INT).addNullable("null2", MinorType.VARCHAR).addMap("map2").addNullable("null3", MinorType.INT).resumeMap().resumeSchema().add("d", MinorType.VARCHAR).buildSchema();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, mapValue(null, null, singleMap(null)), "barney").addRow(20, mapValue(null, null, singleMap(null)), "wilma").build();
new RowSetComparison(expected).verifyAndClearAll(result);
resolvedTuple.close();
}
Aggregations