use of org.apache.drill.exec.physical.resultSet.ResultVectorCache 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();
}
use of org.apache.drill.exec.physical.resultSet.ResultVectorCache in project drill by apache.
the class TestMissingColumnLoader method testCustomNullType.
/**
* Test the ability to use a type other than nullable INT for null
* columns. This occurs, for example, in the CSV reader where no
* column is ever INT (nullable or otherwise) and we want our null
* columns to be (non-nullable) VARCHAR.
*/
@Test
public void testCustomNullType() {
TupleMetadata missingCols = new SchemaBuilder().addDynamic("unspecified").build();
// Null required is an oxymoron, so is not tested.
// Null type array does not make sense, so is not tested.
final ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
final MajorType nullType = MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.OPTIONAL).build();
StaticBatchBuilder handler = new MissingColumnHandlerBuilder().inputSchema(missingCols).vectorCache(cache).nullType(nullType).build();
assertNotNull(handler);
// Create a batch
handler.load(2);
// Verify values and types
final TupleMetadata expectedSchema = new SchemaBuilder().add("unspecified", nullType).buildSchema();
final SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addSingleCol(null).addSingleCol(null).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 TestMissingColumnLoader method testEmpty.
@Test
public void testEmpty() {
TupleMetadata missingCols = new SchemaBuilder().build();
final ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
StaticBatchBuilder handler = new MissingColumnHandlerBuilder().inputSchema(missingCols).vectorCache(cache).build();
assertNull(handler);
}
use of org.apache.drill.exec.physical.resultSet.ResultVectorCache in project drill by apache.
the class TestMissingColumnLoader 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() {
TupleMetadata missingCols = new SchemaBuilder().addDynamic("unspecified").addNullable("specifiedOpt", MinorType.VARCHAR).add("specifiedReq", MinorType.VARCHAR).addArray("specifiedArray", MinorType.VARCHAR).build();
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("unspecified", MissingColumnHandlerBuilder.DEFAULT_NULL_TYPE).addNullable("specifiedOpt", MinorType.VARCHAR).add("specifiedReq", MinorType.VARCHAR).addArray("specifiedArray", MinorType.VARCHAR).buildSchema();
final SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(null, null, "", new String[] {}).addRow(null, null, "", new String[] {}).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 TestMissingColumnLoader method testAllModes.
/**
* More extensive schema test.
*/
@Test
public void testAllModes() {
final TupleMetadata missingCols = new SchemaBuilder().add("intReq", MinorType.INT).add("strReq", MinorType.VARCHAR).add("dubReq", // No default
MinorType.FLOAT8).addNullable("intOpt", MinorType.INT).addNullable("strOpt", MinorType.VARCHAR).addNullable("dubOpt", MinorType.FLOAT8).buildSchema();
missingCols.metadata("intReq").setDefaultValue("10");
missingCols.metadata("strReq").setDefaultValue("foo");
missingCols.metadata("intOpt").setDefaultValue("20");
missingCols.metadata("strOpt").setDefaultValue("bar");
final ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
StaticBatchBuilder handler = new MissingColumnHandlerBuilder().inputSchema(missingCols).vectorCache(cache).nullType(Types.optional(MinorType.VARCHAR)).build();
assertNotNull(handler);
handler.load(2);
final SingleRowSet expected = fixture.rowSetBuilder(missingCols).addRow(10, "foo", 0.0D, null, null, null).addRow(10, "foo", 0.0D, null, null, null).build();
RowSetUtilities.verify(expected, fixture.wrap(handler.outputContainer()));
handler.close();
}
Aggregations