Search in sources :

Example 26 with NullBuilderBuilder

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);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) NullBuilderBuilder(org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder) VectorContainer(org.apache.drill.exec.record.VectorContainer) ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResolvedRow(org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) NullResultVectorCacheImpl(org.apache.drill.exec.physical.resultSet.impl.NullResultVectorCacheImpl) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 27 with NullBuilderBuilder

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();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) NullBuilderBuilder(org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder) VectorContainer(org.apache.drill.exec.record.VectorContainer) ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResolvedRow(org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) NullResultVectorCacheImpl(org.apache.drill.exec.physical.resultSet.impl.NullResultVectorCacheImpl) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

NullBuilderBuilder (org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder)27 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)26 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)26 SubOperatorTest (org.apache.drill.test.SubOperatorTest)26 Test (org.junit.Test)26 ResolvedRow (org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow)24 ResultVectorCache (org.apache.drill.exec.physical.resultSet.ResultVectorCache)7 NullResultVectorCacheImpl (org.apache.drill.exec.physical.resultSet.impl.NullResultVectorCacheImpl)7 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)7 ImplicitColumnManager (org.apache.drill.exec.physical.impl.scan.file.ImplicitColumnManager)4 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)4 VectorContainer (org.apache.drill.exec.record.VectorContainer)4 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)4 Path (org.apache.hadoop.fs.Path)4 ExplicitSchemaProjection (org.apache.drill.exec.physical.impl.scan.project.ExplicitSchemaProjection)3 NullColumnBuilder (org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder)3 ResolvedColumn (org.apache.drill.exec.physical.impl.scan.project.ResolvedColumn)3 ScanLevelProjection (org.apache.drill.exec.physical.impl.scan.project.ScanLevelProjection)3 UserException (org.apache.drill.common.exceptions.UserException)2 FileMetadataColumn (org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn)2