Search in sources :

Example 6 with ResultVectorCache

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();
}
Also used : ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) 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) EvfTest(org.apache.drill.categories.EvfTest)

Example 7 with ResultVectorCache

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();
}
Also used : ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) 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) NullBuilderBuilder(org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 8 with ResultVectorCache

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();
}
Also used : ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) ArrayList(java.util.ArrayList) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) NullResultVectorCacheImpl(org.apache.drill.exec.physical.resultSet.impl.NullResultVectorCacheImpl) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 9 with ResultVectorCache

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);
}
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 10 with ResultVectorCache

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);
}
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)

Aggregations

ResultVectorCache (org.apache.drill.exec.physical.resultSet.ResultVectorCache)18 SubOperatorTest (org.apache.drill.test.SubOperatorTest)18 Test (org.junit.Test)18 NullResultVectorCacheImpl (org.apache.drill.exec.physical.resultSet.impl.NullResultVectorCacheImpl)15 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)15 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)15 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)14 NullBuilderBuilder (org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder)7 VectorContainer (org.apache.drill.exec.record.VectorContainer)7 EvfTest (org.apache.drill.categories.EvfTest)5 ResolvedRow (org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow)4 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)4 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)4 ArrayList (java.util.ArrayList)3 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)3 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 ValueVector (org.apache.drill.exec.vector.ValueVector)2 IntVector (org.apache.drill.exec.vector.IntVector)1