Search in sources :

Example 1 with RequestedColumn

use of org.apache.drill.exec.physical.resultSet.project.RequestedColumn 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 2 with RequestedColumn

use of org.apache.drill.exec.physical.resultSet.project.RequestedColumn 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 3 with RequestedColumn

use of org.apache.drill.exec.physical.resultSet.project.RequestedColumn in project drill by apache.

the class ExplicitSchemaProjection method resolveMapMembers.

/**
 * A child column of a map is not projected. Recurse to determine the full
 * set of nullable child columns.
 *
 * @param outputTuple projected tuple being built
 * @param col the map column which was projected
 * @return a list of null markers for the requested children
 */
private ResolvedColumn resolveMapMembers(ResolvedTuple outputTuple, RequestedColumn col) {
    ResolvedMapColumn mapCol = new ResolvedMapColumn(outputTuple, col.name());
    ResolvedTuple members = mapCol.members();
    for (RequestedColumn child : col.tuple().projections()) {
        if (child.isTuple()) {
            members.add(resolveMapMembers(members, child));
        } else {
            members.add(outputTuple.nullBuilder.add(child.name()));
        }
    }
    return mapCol;
}
Also used : RequestedColumn(org.apache.drill.exec.physical.resultSet.project.RequestedColumn)

Example 4 with RequestedColumn

use of org.apache.drill.exec.physical.resultSet.project.RequestedColumn in project drill by apache.

the class ScanLevelProjection method doParse.

private void doParse() {
    outputProjection = Projections.parse(projectionList);
    switch(outputProjection.type()) {
        case ALL:
            includesWildcard = true;
            projectionType = ScanProjectionType.WILDCARD;
            break;
        case NONE:
            projectionType = ScanProjectionType.EMPTY;
            break;
        default:
            projectionType = ScanProjectionType.EXPLICIT;
            break;
    }
    for (ScanProjectionParser parser : parsers) {
        parser.bind(this);
    }
    // Process projected columns.
    for (RequestedColumn inCol : outputProjection.projections()) {
        if (inCol.isWildcard()) {
            mapWildcard(inCol);
        } else {
            mapColumn(inCol);
        }
    }
    verify();
    for (ScanProjectionParser parser : parsers) {
        parser.build();
    }
    buildReaderProjection();
}
Also used : RequestedColumn(org.apache.drill.exec.physical.resultSet.project.RequestedColumn)

Aggregations

RequestedColumn (org.apache.drill.exec.physical.resultSet.project.RequestedColumn)4 EvfTest (org.apache.drill.categories.EvfTest)2 UnresolvedColumn (org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn)2 ProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter)2 RequestedTuple (org.apache.drill.exec.physical.resultSet.project.RequestedTuple)2 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)2 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)2 SubOperatorTest (org.apache.drill.test.SubOperatorTest)2 Test (org.junit.Test)2