use of org.apache.drill.exec.physical.resultSet.ResultVectorCache in project drill by apache.
the class TestMissingColumnLoader method testDefaultValue.
/**
* Test the ability to provide a default value for a "null" column.
* Default values are only allowed for required "null" columns. For
* nullable columns, NULL is already the default.
*/
@Test
public void testDefaultValue() {
TupleMetadata missingCols = new SchemaBuilder().add("int", MinorType.INT).add("str", MinorType.VARCHAR).add("dub", MinorType.FLOAT8).build();
missingCols.metadata("int").setDefaultValue("10");
missingCols.metadata("str").setDefaultValue("foo");
missingCols.metadata("dub").setDefaultValue("20.0");
final ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
StaticBatchBuilder handler = new MissingColumnHandlerBuilder().inputSchema(missingCols).vectorCache(cache).build();
assertNotNull(handler);
// Create a batch
handler.load(2);
// Verify values and types
final TupleMetadata expectedSchema = new SchemaBuilder().add("int", MinorType.INT).add("str", MinorType.VARCHAR).add("dub", MinorType.FLOAT8).buildSchema();
final SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, "foo", 20.0D).addRow(10, "foo", 20.0D).build();
RowSetUtilities.verify(expected, fixture.wrap(handler.outputContainer()));
handler.close();
}
use of org.apache.drill.exec.physical.resultSet.ResultVectorCache in project drill by apache.
the class TestNullColumnLoader method testNullColumnBuilder.
/**
* Test the shim class that adapts between the null column loader
* and the projection mechanism. The projection mechanism uses this
* to pull in the null columns which the null column loader has
* created.
*/
@Test
public void testNullColumnBuilder() {
final ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
final NullColumnBuilder builder = new NullBuilderBuilder().build();
builder.add("unspecified");
builder.add("nullType", Types.optional(MinorType.NULL));
builder.add("specifiedOpt", Types.optional(MinorType.VARCHAR));
builder.add("specifiedReq", Types.required(MinorType.VARCHAR));
builder.add("specifiedArray", Types.repeated(MinorType.VARCHAR));
builder.build(cache);
// Create a batch
builder.load(2);
// Verify values and types
final TupleMetadata expectedSchema = new SchemaBuilder().add("unspecified", NullColumnLoader.DEFAULT_NULL_TYPE).add("nullType", NullColumnLoader.DEFAULT_NULL_TYPE).addNullable("specifiedOpt", MinorType.VARCHAR).addNullable("specifiedReq", MinorType.VARCHAR).addArray("specifiedArray", MinorType.VARCHAR).buildSchema();
final SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(null, null, null, null, new String[] {}).addRow(null, null, null, null, new String[] {}).build();
RowSetUtilities.verify(expected, fixture.wrap(builder.output()));
builder.close();
}
use of org.apache.drill.exec.physical.resultSet.ResultVectorCache in project drill by apache.
the class TestNullColumnLoader method testBasics.
/**
* Test the simplest case: default null type, nothing in the vector
* cache. Specify no column type, the special NULL type, or a
* predefined type. Output types should be set accordingly.
*/
@Test
public void testBasics() {
final List<ResolvedNullColumn> defns = new ArrayList<>();
defns.add(makeNullCol("unspecified", null));
defns.add(makeNullCol("nullType", Types.optional(MinorType.NULL)));
defns.add(makeNullCol("specifiedOpt", Types.optional(MinorType.VARCHAR)));
defns.add(makeNullCol("specifiedReq", Types.required(MinorType.VARCHAR)));
defns.add(makeNullCol("specifiedArray", Types.repeated(MinorType.VARCHAR)));
final ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
final NullColumnLoader staticLoader = new NullColumnLoader(cache, defns, null, false);
// Create a batch
final VectorContainer output = staticLoader.load(2);
// Verify values and types
final TupleMetadata expectedSchema = new SchemaBuilder().add("unspecified", NullColumnLoader.DEFAULT_NULL_TYPE).add("nullType", NullColumnLoader.DEFAULT_NULL_TYPE).addNullable("specifiedOpt", MinorType.VARCHAR).addNullable("specifiedReq", MinorType.VARCHAR).addArray("specifiedArray", MinorType.VARCHAR).buildSchema();
final SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(null, null, null, null, new String[] {}).addRow(null, null, null, null, new String[] {}).build();
RowSetUtilities.verify(expected, fixture.wrap(output));
staticLoader.close();
}
use of org.apache.drill.exec.physical.resultSet.ResultVectorCache in project drill by apache.
the class TestRowBatchMerger method testMapArrayRevision.
/**
* Test that the merger mechanism can rewrite a map array to include
* projected null columns.
*/
@Test
public void testMapArrayRevision() {
// Create the first batch
TupleMetadata inputSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).addMapArray("a").add("c", MinorType.INT).resumeSchema().buildSchema();
RowSetSource input = new RowSetSource(fixture.rowSetBuilder(inputSchema).addRow("barney", mapArray(singleMap(10), singleMap(11), singleMap(12))).addRow("wilma", mapArray(singleMap(20), singleMap(21))).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).addMapArray("a").add("c", MinorType.INT).addNullable("null1", MinorType.INT).resumeSchema().buildSchema();
RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow("barney", mapArray(mapValue(10, null), mapValue(11, null), mapValue(12, null))).addRow("wilma", mapArray(mapValue(20, null), mapValue(21, null))).build();
new RowSetComparison(expected).verifyAndClearAll(result);
}
use of org.apache.drill.exec.physical.resultSet.ResultVectorCache 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);
}
Aggregations