Search in sources :

Example 11 with ResultVectorCache

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

Example 12 with ResultVectorCache

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();
}
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) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) 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 13 with ResultVectorCache

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);
}
Also used : ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) 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 14 with ResultVectorCache

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

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

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