Search in sources :

Example 11 with ResolvedRow

use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.

the class TestReaderLevelProjection method testWildcardWithStrictSchema.

/**
 * Strict metadata schema. Projects output the output schema
 * columns; ignores other reader columns.
 */
@Test
public void testWildcardWithStrictSchema() {
    TupleMetadata outputSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
    outputSchema.setProperty(TupleMetadata.IS_STRICT_SCHEMA_PROP, Boolean.TRUE.toString());
    // Simulate SELECT * ...
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers(), outputSchema);
    assertEquals(2, scanProj.columns().size());
    // Simulate a data source, with early schema, of (b, c)
    final TupleMetadata tableSchema = new SchemaBuilder().add("B", MinorType.VARCHAR).add("C", MinorType.VARCHAR).buildSchema();
    final NullColumnBuilder builder = new NullBuilderBuilder().build();
    final ResolvedRow rootTuple = new ResolvedRow(builder);
    new WildcardSchemaProjection(scanProj, tableSchema, rootTuple, ScanTestUtils.resolvers());
    final List<ResolvedColumn> columns = rootTuple.columns();
    assertEquals(2, columns.size());
    ResolvedColumn aCol = columns.get(0);
    assertEquals("a", aCol.name());
    assertTrue(aCol instanceof ResolvedNullColumn);
    assertNotNull(aCol.metadata());
    assertSame(outputSchema.metadata("a"), aCol.metadata());
    ResolvedColumn bCol = columns.get(1);
    assertEquals("b", bCol.name());
    assertTrue(bCol instanceof ResolvedTableColumn);
    assertNotNull(bCol.metadata());
    assertSame(outputSchema.metadata("b"), bCol.metadata());
    final VectorSource nullBuilder = rootTuple.nullBuilder();
    assertSame(nullBuilder, columns.get(0).source());
}
Also used : 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) NullBuilderBuilder(org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 12 with ResolvedRow

use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.

the class TestReaderLevelProjection method testMissing.

/**
 * Test SELECT list with columns missing from the table schema.
 */
@Test
public void testMissing() {
    // Simulate SELECT c, v, b, w ...
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("c", "v", "b", "w"), ScanTestUtils.parsers());
    assertEquals(4, scanProj.columns().size());
    // Simulate a data source, with early schema, of (a, b, c)
    final TupleMetadata tableSchema = new SchemaBuilder().add("A", MinorType.VARCHAR).add("B", MinorType.VARCHAR).add("C", MinorType.VARCHAR).buildSchema();
    final NullColumnBuilder builder = new NullBuilderBuilder().build();
    final ResolvedRow rootTuple = new ResolvedRow(builder);
    new ExplicitSchemaProjection(scanProj, tableSchema, rootTuple, ScanTestUtils.resolvers());
    final List<ResolvedColumn> columns = rootTuple.columns();
    assertEquals(4, columns.size());
    final VectorSource nullBuilder = rootTuple.nullBuilder();
    assertEquals("c", columns.get(0).name());
    assertEquals(2, columns.get(0).sourceIndex());
    assertSame(rootTuple, columns.get(0).source());
    assertEquals("v", columns.get(1).name());
    assertEquals(0, columns.get(1).sourceIndex());
    assertSame(nullBuilder, columns.get(1).source());
    assertEquals("b", columns.get(2).name());
    assertEquals(1, columns.get(2).sourceIndex());
    assertSame(rootTuple, columns.get(2).source());
    assertEquals("w", columns.get(3).name());
    assertEquals(1, columns.get(3).sourceIndex());
    assertSame(nullBuilder, columns.get(3).source());
}
Also used : 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) NullBuilderBuilder(org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 13 with ResolvedRow

use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.

the class TestReaderLevelProjection method testOmittedMap.

/**
 * Test the obscure case that the data source contains a map, but we
 * project only one of the members of the map. The output should be a
 * map that contains only the members we request.
 */
@Test
public void testOmittedMap() {
    // Simulate SELECT a, b.c.d ...
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a", "b.c.d"), ScanTestUtils.parsers());
    assertEquals(2, scanProj.columns().size());
    {
        assertTrue(scanProj.columns().get(1) instanceof UnresolvedColumn);
        final UnresolvedColumn bCol = (UnresolvedColumn) (scanProj.columns().get(1));
        assertTrue(bCol.element().isTuple());
    }
    // Simulate a data source, with early schema, of (a)
    final TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).buildSchema();
    final NullColumnBuilder builder = new NullBuilderBuilder().build();
    final ResolvedRow rootTuple = new ResolvedRow(builder);
    new ExplicitSchemaProjection(scanProj, tableSchema, rootTuple, ScanTestUtils.resolvers());
    final List<ResolvedColumn> columns = rootTuple.columns();
    assertEquals(2, columns.size());
    // Should have resolved a to a table column, b to a missing map.
    // A is projected
    final ResolvedColumn aCol = columns.get(0);
    assertEquals("a", aCol.name());
    assertTrue(aCol instanceof ResolvedTableColumn);
    // B is not projected, is implicitly a map
    final ResolvedColumn bCol = columns.get(1);
    assertEquals("b", bCol.name());
    assertTrue(bCol instanceof ResolvedMapColumn);
    final ResolvedMapColumn bMap = (ResolvedMapColumn) bCol;
    final ResolvedTuple bMembers = bMap.members();
    assertNotNull(bMembers);
    assertEquals(1, bMembers.columns().size());
    // C is a map within b
    final ResolvedColumn cCol = bMembers.columns().get(0);
    assertTrue(cCol instanceof ResolvedMapColumn);
    final ResolvedMapColumn cMap = (ResolvedMapColumn) cCol;
    final ResolvedTuple cMembers = cMap.members();
    assertNotNull(cMembers);
    assertEquals(1, cMembers.columns().size());
    // D is an unknown column type (not a map)
    final ResolvedColumn dCol = cMembers.columns().get(0);
    assertTrue(dCol instanceof ResolvedNullColumn);
}
Also used : NullBuilderBuilder(org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder) ResolvedRow(org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow) UnresolvedColumn(org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 14 with ResolvedRow

use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.

the class TestReaderLevelProjection method testDisjoint.

/**
 * Drill is unique in that we can select (a, b) from a data source
 * that only offers (c, d). We get null columns as a result.
 */
@Test
public void testDisjoint() {
    // Simulate SELECT c, a ...
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("b"), ScanTestUtils.parsers());
    assertEquals(1, scanProj.columns().size());
    // Simulate a data source, with early schema, of (a)
    final TupleMetadata tableSchema = new SchemaBuilder().add("A", MinorType.VARCHAR).buildSchema();
    final NullColumnBuilder builder = new NullBuilderBuilder().build();
    final ResolvedRow rootTuple = new ResolvedRow(builder);
    new ExplicitSchemaProjection(scanProj, tableSchema, rootTuple, ScanTestUtils.resolvers());
    final List<ResolvedColumn> columns = rootTuple.columns();
    assertEquals(1, columns.size());
    final VectorSource nullBuilder = rootTuple.nullBuilder();
    assertEquals("b", columns.get(0).name());
    assertEquals(0, columns.get(0).sourceIndex());
    assertSame(nullBuilder, columns.get(0).source());
}
Also used : 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) NullBuilderBuilder(org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 15 with ResolvedRow

use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.

the class TestRowBatchMerger method testFlatWithNulls.

@Test
public void testFlatWithNulls() {
    // 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));
    resolvedTuple.add(resolvedTuple.nullBuilder().add("null1"));
    resolvedTuple.add(resolvedTuple.nullBuilder().add("null2", Types.optional(MinorType.VARCHAR)));
    resolvedTuple.add(new TestProjection(resolvedTuple, 0));
    // Build the null values
    ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
    builder.build(cache);
    builder.load(first.rowSet().rowCount());
    // Do the merge
    VectorContainer output = new VectorContainer(fixture.allocator());
    resolvedTuple.project(first.rowSet().container(), output);
    output.setRecordCount(first.rowSet().rowCount());
    RowSet result = fixture.wrap(output);
    // Verify
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("null1", MinorType.INT).addNullable("null2", MinorType.VARCHAR).add("d", MinorType.VARCHAR).buildSchema();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, null, null, "barney").addRow(20, null, null, "wilma").build();
    new RowSetComparison(expected).verifyAndClearAll(result);
    builder.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

ResolvedRow (org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow)37 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)36 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)36 SubOperatorTest (org.apache.drill.test.SubOperatorTest)36 Test (org.junit.Test)36 NullBuilderBuilder (org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder)24 ImplicitColumnManager (org.apache.drill.exec.physical.impl.scan.file.ImplicitColumnManager)7 Path (org.apache.hadoop.fs.Path)7 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)6 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)6 VectorContainer (org.apache.drill.exec.record.VectorContainer)6 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)6 ResultVectorCache (org.apache.drill.exec.physical.resultSet.ResultVectorCache)4 NullResultVectorCacheImpl (org.apache.drill.exec.physical.resultSet.impl.NullResultVectorCacheImpl)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 List (java.util.List)2 UserException (org.apache.drill.common.exceptions.UserException)2