Search in sources :

Example 6 with UnresolvedColumn

use of org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn in project drill by apache.

the class TestScanLevelProjection method testArray.

/**
 * Similar to maps, if the project list contains "a[1]" then we've learned that
 * a is an array, but we don't know what type.
 */
@Test
public void testArray() {
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a[1]", "a[3]"), ScanTestUtils.parsers());
    assertFalse(scanProj.projectAll());
    assertFalse(scanProj.isEmptyProjection());
    assertEquals(1, scanProj.columns().size());
    assertEquals("a", scanProj.columns().get(0).name());
    // Verify column type
    assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumn);
    // Map structure
    final RequestedColumn a = ((UnresolvedColumn) scanProj.columns().get(0)).element();
    assertTrue(a.isArray());
    assertFalse(a.hasIndex(0));
    assertTrue(a.hasIndex(1));
    assertFalse(a.hasIndex(2));
    assertTrue(a.hasIndex(3));
    // Verify tuple projection
    RequestedTuple outputProj = scanProj.rootProjection();
    assertEquals(1, outputProj.projections().size());
    assertNotNull(outputProj.get("a"));
    assertTrue(outputProj.get("a").isArray());
    // Make up a reader schema and test the projection set.
    TupleMetadata readerSchema = new SchemaBuilder().addArray("a", MinorType.INT).add("c", MinorType.INT).buildSchema();
    ProjectionFilter projSet = scanProj.readerProjection();
    assertTrue(isProjected(projSet, readerSchema.metadata("a")));
    assertFalse(isProjected(projSet, readerSchema.metadata("c")));
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) UnresolvedColumn(org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn) RequestedTuple(org.apache.drill.exec.physical.resultSet.project.RequestedTuple) RequestedColumn(org.apache.drill.exec.physical.resultSet.project.RequestedColumn) 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) EvfTest(org.apache.drill.categories.EvfTest)

Example 7 with UnresolvedColumn

use of org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn in project drill by apache.

the class TestScanLevelProjection method testStrictProvidedSchemaWildcard.

/**
 * Wildcard projection with a strict schema is the same as a non-strict
 * schema, except that the projection type is different.
 */
@Test
public void testStrictProvidedSchemaWildcard() {
    TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
    providedSchema.setProperty(TupleMetadata.IS_STRICT_SCHEMA_PROP, Boolean.TRUE.toString());
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers(), providedSchema);
    assertEquals(ScanProjectionType.STRICT_SCHEMA_WILDCARD, scanProj.projectionType());
    assertEquals(2, scanProj.columns().size());
    assertEquals("a", scanProj.columns().get(0).name());
    assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumn);
    assertEquals("b", scanProj.columns().get(1).name());
    assertTrue(scanProj.columns().get(1) instanceof UnresolvedColumn);
    // Make up a reader schema and test the projection set.
    TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).add("c", MinorType.INT).buildSchema();
    ProjectionFilter projSet = scanProj.readerProjection();
    assertTrue(isProjected(projSet, readerSchema.metadata("a")));
    assertTrue(isProjected(projSet, readerSchema.metadata("b")));
    assertFalse(isProjected(projSet, readerSchema.metadata("c")));
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) 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) EvfTest(org.apache.drill.categories.EvfTest)

Example 8 with UnresolvedColumn

use of org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn in project drill by apache.

the class TestScanLevelProjection method testMap.

/**
 * Map projection occurs when a query contains project-list items with
 * a dot, such as "a.b". We may not know the type of "b", but have
 * just learned that "a" must be a map.
 */
@Test
public void testMap() {
    // SELECT a.x, b.x, a.y, b.y, c
    // We infer a and b are maps.
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a.x", "b.x", "a.y", "b.y", "c"), ScanTestUtils.parsers());
    assertFalse(scanProj.projectAll());
    assertFalse(scanProj.isEmptyProjection());
    assertEquals(3, scanProj.columns().size());
    assertEquals("a", scanProj.columns().get(0).name());
    assertEquals("b", scanProj.columns().get(1).name());
    assertEquals("c", scanProj.columns().get(2).name());
    // Verify column type
    assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumn);
    // Inferred map structure
    final RequestedColumn a = ((UnresolvedColumn) scanProj.columns().get(0)).element();
    assertTrue(a.isTuple());
    assertTrue(a.tuple().isProjected("x"));
    assertTrue(a.tuple().isProjected("y"));
    assertFalse(a.tuple().isProjected("z"));
    final RequestedColumn c = ((UnresolvedColumn) scanProj.columns().get(2)).element();
    assertTrue(c.isSimple());
    // Verify tuple projection
    RequestedTuple outputProj = scanProj.rootProjection();
    assertEquals(3, outputProj.projections().size());
    assertNotNull(outputProj.get("a"));
    assertTrue(outputProj.get("a").isTuple());
    // Make up a reader schema and test the projection set.
    TupleMetadata readerSchema = new SchemaBuilder().addMap("a").add("x", MinorType.INT).add("y", MinorType.INT).resumeSchema().addMap("b").add("x", MinorType.INT).add("y", MinorType.INT).resumeSchema().add("c", MinorType.INT).add("d", MinorType.INT).buildSchema();
    // Verify the projection set as if we were a reader. Note that the
    // projection type is used here for testing; should not be used by
    // an actual reader.
    ProjectionFilter projSet = scanProj.readerProjection();
    assertTrue(isProjected(projSet, readerSchema.metadata("a")));
    assertTrue(isProjected(projSet, readerSchema.metadata("c")));
    assertFalse(isProjected(projSet, readerSchema.metadata("d")));
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) UnresolvedColumn(org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn) RequestedTuple(org.apache.drill.exec.physical.resultSet.project.RequestedTuple) RequestedColumn(org.apache.drill.exec.physical.resultSet.project.RequestedColumn) 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) EvfTest(org.apache.drill.categories.EvfTest)

Example 9 with UnresolvedColumn

use of org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn in project drill by apache.

the class TestScanLevelProjection method testProvidedSchemaWildcard.

@Test
public void testProvidedSchemaWildcard() {
    TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers(), providedSchema);
    assertEquals(ScanProjectionType.SCHEMA_WILDCARD, scanProj.projectionType());
    assertEquals(2, scanProj.columns().size());
    ColumnProjection aCol = scanProj.columns().get(0);
    assertEquals("a", aCol.name());
    assertTrue(aCol instanceof UnresolvedColumn);
    assertSame(providedSchema.metadata("a"), ((UnresolvedColumn) aCol).metadata());
    ColumnProjection bCol = scanProj.columns().get(1);
    assertEquals("b", bCol.name());
    assertTrue(bCol instanceof UnresolvedColumn);
    assertSame(providedSchema.metadata("b"), ((UnresolvedColumn) bCol).metadata());
    ProjectionFilter projSet = scanProj.readerProjection();
    assertTrue(isProjected(projSet, providedSchema.metadata("a")));
    assertTrue(isProjected(projSet, providedSchema.metadata("b")));
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) 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) EvfTest(org.apache.drill.categories.EvfTest)

Example 10 with UnresolvedColumn

use of org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn in project drill by apache.

the class TestImplicitColumnParser method testShadowed.

/**
 * Verify that names that look like metadata columns, but appear
 * to be maps or arrays, are not interpreted as metadata. That is,
 * the projected table map or array "shadows" the metadata column.
 */
@Test
public void testShadowed() {
    Path filePath = new Path("hdfs:///w/x/y/z.csv");
    ImplicitColumnManager implictColManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
    ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(ScanTestUtils.FILE_NAME_COL + ".a", ScanTestUtils.FILE_PATH_COL + "[0]", ScanTestUtils.partitionColName(0) + ".b", ScanTestUtils.partitionColName(1) + "[0]", ScanTestUtils.SUFFIX_COL), Lists.newArrayList(implictColManager.projectionParser()));
    List<ColumnProjection> cols = scanProj.columns();
    assertEquals(5, cols.size());
    for (int i = 0; i < 4; i++) {
        assertTrue(scanProj.columns().get(i) instanceof UnresolvedColumn);
    }
    assertTrue(scanProj.columns().get(4) instanceof FileMetadataColumn);
}
Also used : SchemaPath(org.apache.drill.common.expression.SchemaPath) Path(org.apache.hadoop.fs.Path) ImplicitColumnManager(org.apache.drill.exec.physical.impl.scan.file.ImplicitColumnManager) ScanLevelProjection(org.apache.drill.exec.physical.impl.scan.project.ScanLevelProjection) UnresolvedColumn(org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn) ColumnProjection(org.apache.drill.exec.physical.impl.scan.project.ColumnProjection) FileMetadataColumn(org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

UnresolvedColumn (org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn)12 SubOperatorTest (org.apache.drill.test.SubOperatorTest)10 Test (org.junit.Test)10 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)8 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)8 EvfTest (org.apache.drill.categories.EvfTest)6 ProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter)5 FileMetadataColumn (org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn)3 ImplicitColumnManager (org.apache.drill.exec.physical.impl.scan.file.ImplicitColumnManager)3 ScanLevelProjection (org.apache.drill.exec.physical.impl.scan.project.ScanLevelProjection)3 RequestedTuple (org.apache.drill.exec.physical.resultSet.project.RequestedTuple)3 Path (org.apache.hadoop.fs.Path)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)2 ColumnProjection (org.apache.drill.exec.physical.impl.scan.project.ColumnProjection)2 NullBuilderBuilder (org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder)2 ResolvedRow (org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow)2 RequestedColumn (org.apache.drill.exec.physical.resultSet.project.RequestedColumn)2 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)2 PartitionColumn (org.apache.drill.exec.physical.impl.scan.file.PartitionColumn)1 ExplicitSchemaProjection (org.apache.drill.exec.physical.impl.scan.project.ExplicitSchemaProjection)1