Search in sources :

Example 6 with NullBuilderBuilder

use of org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder in project drill by apache.

the class TestReaderLevelProjection method testSimpleMapProject.

/**
 * Simple map project. This is an internal case in which the
 * query asks for a set of columns inside a map, and the table
 * loader produces exactly that set. No special projection is
 * needed, the map is projected as a whole.
 */
@Test
public void testSimpleMapProject() {
    // Simulate SELECT a.b, a.c ...
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a.b", "a.c"), ScanTestUtils.parsers());
    assertEquals(1, scanProj.columns().size());
    // Simulate a data source, with early schema, of (a{b, c})
    final TupleMetadata tableSchema = new SchemaBuilder().addMap("a").add("b", MinorType.BIGINT).add("c", MinorType.FLOAT8).resumeSchema().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());
    // Should have resolved a.b to a map column,
    // a.d to a missing nested map, and a.e.f to a missing
    // nested map member
    // a is projected as a vector, not as a structured map
    final ResolvedColumn aCol = columns.get(0);
    assertEquals("a", aCol.name());
    assertTrue(aCol instanceof ResolvedTableColumn);
    assertSame(rootTuple, aCol.source());
    assertEquals(0, aCol.sourceIndex());
}
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 7 with NullBuilderBuilder

use of org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder in project drill by apache.

the class TestReaderLevelProjection method testArrayMismatch.

/**
 * Project of a non-array as an array
 */
@Test
public void testArrayMismatch() {
    // Simulate SELECT a[0] ...
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a[0]"), ScanTestUtils.parsers());
    // Simulate a data source, with early schema, of (a)
    // where a is not an array.
    final TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).buildSchema();
    final NullColumnBuilder builder = new NullBuilderBuilder().build();
    final ResolvedRow rootTuple = new ResolvedRow(builder);
    try {
        new ExplicitSchemaProjection(scanProj, tableSchema, rootTuple, ScanTestUtils.resolvers());
        fail();
    } catch (final UserException e) {
    // Expected
    }
}
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) UserException(org.apache.drill.common.exceptions.UserException) NullBuilderBuilder(org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 8 with NullBuilderBuilder

use of org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder in project drill by apache.

the class TestReaderLevelProjection method testArrayProject.

/**
 * Test project of an array. At the scan level, we just verify
 * that the requested column is, indeed, an array.
 */
@Test
public void testArrayProject() {
    // Simulate SELECT a[0] ...
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a[0]"), ScanTestUtils.parsers());
    // Simulate a data source, with early schema, of (a)
    // where a is not an array.
    final TupleMetadata tableSchema = new SchemaBuilder().addArray("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 ResolvedColumn aCol = columns.get(0);
    assertEquals("a", aCol.name());
    assertTrue(aCol instanceof ResolvedTableColumn);
    assertSame(rootTuple, aCol.source());
    assertEquals(0, aCol.sourceIndex());
}
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 9 with NullBuilderBuilder

use of org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder in project drill by apache.

the class TestReaderLevelProjection method testWildcardWithSchema.

/**
 * Non-strict metadata schema. Projects all schema columns
 * followed by any "extra" reader columns.
 */
@Test
public void testWildcardWithSchema() {
    TupleMetadata outputSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
    // 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(3, columns.size());
    // Columns from schema preferentially use schema-defined names
    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());
    // Non-schema columns use reader names
    ResolvedColumn cCol = columns.get(2);
    assertEquals("C", cCol.name());
    assertTrue(cCol instanceof ResolvedTableColumn);
    assertNull(cCol.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 10 with NullBuilderBuilder

use of org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder in project drill by apache.

the class TestReaderLevelProjection method testFullList.

/**
 * Test SELECT list with columns defined in a order and with
 * name case different than the early-schema table.
 */
@Test
public void testFullList() {
    // Simulate SELECT c, b, a ...
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("c", "b", "a"), ScanTestUtils.parsers());
    assertEquals(3, 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(3, columns.size());
    assertEquals("c", columns.get(0).name());
    assertEquals(2, columns.get(0).sourceIndex());
    assertSame(rootTuple, columns.get(0).source());
    assertEquals("b", columns.get(1).name());
    assertEquals(1, columns.get(1).sourceIndex());
    assertSame(rootTuple, columns.get(1).source());
    assertEquals("a", columns.get(2).name());
    assertEquals(0, columns.get(2).sourceIndex());
    assertSame(rootTuple, columns.get(2).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)

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