Search in sources :

Example 26 with ProjectionFilter

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

the class TestScanSchemaTrackerMaps method doTestMapDefinedSchema.

private void doTestMapDefinedSchema(ScanSchemaConfigBuilder builder, TupleMetadata targetSchema) {
    final ScanSchemaTracker schemaTracker = builder.build();
    assertTrue(schemaTracker.isResolved());
    // Pretend the reader reads one of the map columns and discovers a new one.
    TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
    assertEquals(targetSchema, reader1InputSchema);
    final TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).resumeSchema().buildSchema();
    {
        ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
        assertTrue(filter instanceof DynamicSchemaFilter);
        assertFalse(filter.isEmpty());
        assertTrue(isProjected(filter, readerOutputSchema.metadata("a")));
        assertTrue(isProjected(filter, readerOutputSchema.metadata("m")));
        assertFalse(filter.isProjected("b"));
        assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(filter, "w").mapFilter);
        final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
        final ProjectionFilter mapFilter = filter.projection(mapCol).mapFilter;
        assertTrue(mapFilter instanceof DynamicSchemaFilter);
        final TupleMetadata mapSchema = mapCol.tupleSchema();
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertTrue(mapFilter.isProjected("y"));
        assertFalse(mapFilter.isProjected("z"));
        assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
    }
    schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
    // Scan output schema is now resolved.
    assertTrue(schemaTracker.isResolved());
    assertEquals(targetSchema, schemaTracker.outputSchema());
    // A second reader gets a strict filter for the row and map.
    TupleMetadata reader2InputSchema = schemaTracker.readerInputSchema();
    assertEquals(targetSchema, reader2InputSchema);
    {
        ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
        assertTrue(filter instanceof DynamicSchemaFilter);
        assertTrue(isProjected(filter, readerOutputSchema.metadata("a")));
        assertTrue(isProjected(filter, readerOutputSchema.metadata("m")));
        assertFalse(filter.isProjected("b"));
        final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
        final ProjectionFilter mapFilter = filter.projection(mapCol).mapFilter;
        assertTrue(mapFilter instanceof DynamicSchemaFilter);
        final TupleMetadata mapSchema = mapCol.tupleSchema();
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertFalse(mapFilter.isProjected("w"));
        assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
    }
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder)

Example 27 with ProjectionFilter

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

the class TestScanSchemaTrackerMaps method testSpecificMapWithLenientProvidedSchema.

/**
 * Test a specific map column ({@code m.x}) with a lenient
 * provided schema. The schema can include columns other than
 * the specific one, but only the specific one will be projected.
 * Note that the projection list, not the provided schema, constrains
 * projection in this case.
 */
@Test
public void testSpecificMapWithLenientProvidedSchema() {
    final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder().projection(RowSetTestUtils.projectList("a", "m.x"));
    final TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).add("y", MinorType.VARCHAR).resumeSchema().buildSchema();
    builder.providedSchema(providedSchema);
    final ScanSchemaTracker schemaTracker = builder.build();
    assertTrue(schemaTracker.isResolved());
    final int initVersion = schemaTracker.schemaVersion();
    // Pretend the reader reads one of the map columns and discovers a new one.
    TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
    assertEquals(2, reader1InputSchema.size());
    final TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).resumeSchema().buildSchema();
    {
        ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
        assertTrue(filter instanceof DynamicSchemaFilter);
        assertTrue(isProjected(filter, readerOutputSchema.metadata("a")));
        assertTrue(isProjected(filter, readerOutputSchema.metadata("m")));
        assertFalse(filter.isProjected("b"));
        assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(filter, "w").mapFilter);
        final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
        final ProjectionFilter mapFilter = filter.projection(mapCol).mapFilter;
        assertTrue(mapFilter instanceof DynamicSchemaFilter);
        final TupleMetadata mapSchema = mapCol.tupleSchema();
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertFalse(mapFilter.isProjected("y"));
        assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
    }
    schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
    assertEquals(initVersion, schemaTracker.schemaVersion());
    // Scan output sent downstream
    assertTrue(schemaTracker.isResolved());
    assertEquals(readerOutputSchema, schemaTracker.outputSchema());
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest) EvfTest(org.apache.drill.categories.EvfTest)

Example 28 with ProjectionFilter

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

the class TestScanSchemaTrackerMaps method testSpecificMap.

/**
 * Test a specific map column, {@code `m`.`x`}, with no schema.
 */
@Test
public void testSpecificMap() {
    final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder().projection(RowSetTestUtils.projectList("a", "m.x"));
    final ScanSchemaTracker schemaTracker = builder.build();
    // Pretend the reader discovers that m is a map.
    TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
    assertEquals(2, reader1InputSchema.size());
    final TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).resumeSchema().buildSchema();
    {
        ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
        assertTrue(filter instanceof DynamicSchemaFilter);
        assertTrue(isProjected(filter, readerOutputSchema.metadata("a")));
        assertTrue(isProjected(filter, readerOutputSchema.metadata("m")));
        assertFalse(filter.isProjected("b"));
        final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
        ProjResult mapResult = filter.projection(mapCol);
        assertTrue(mapResult.isProjected);
        ProjectionFilter mapFilter = mapResult.mapFilter;
        assertTrue(mapFilter instanceof DynamicSchemaFilter);
        final TupleMetadata mapSchema = readerOutputSchema.metadata("m").tupleSchema();
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertFalse(mapFilter.isProjected("y"));
        assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
    }
    schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
    // Scan output schema is now resolved.
    assertTrue(schemaTracker.isResolved());
    final TupleMetadata outputSchema = schemaTracker.outputSchema();
    assertEquals(readerOutputSchema, outputSchema);
    // A second reader gets a strict filter for the row, but a
    // project-all filter for the map.
    TupleMetadata reader2InputSchema = schemaTracker.readerInputSchema();
    assertEquals(outputSchema, reader2InputSchema);
    {
        ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
        assertTrue(filter instanceof DynamicSchemaFilter);
        assertTrue(isProjected(filter, readerOutputSchema.metadata("a")));
        assertTrue(isProjected(filter, readerOutputSchema.metadata("m")));
        assertFalse(filter.isProjected("b"));
        final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
        ProjResult mapResult = filter.projection(mapCol);
        assertTrue(mapResult.isProjected);
        ProjectionFilter mapFilter = mapResult.mapFilter;
        assertTrue(mapFilter instanceof DynamicSchemaFilter);
        final TupleMetadata mapSchema = readerOutputSchema.metadata("m").tupleSchema();
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertFalse(mapFilter.isProjected("y"));
        assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
    }
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ProjResult(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest) EvfTest(org.apache.drill.categories.EvfTest)

Example 29 with ProjectionFilter

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

the class TestScanSchemaTrackerMaps method doTestGenericMapWithSchema.

private void doTestGenericMapWithSchema(ScanSchemaConfigBuilder builder, TupleMetadata targetSchema) {
    final ScanSchemaTracker schemaTracker = builder.build();
    assertTrue(schemaTracker.isResolved());
    final int initVersion = schemaTracker.schemaVersion();
    // Pretend the reader reads one of the map columns and discovers a new one.
    TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
    assertEquals(2, reader1InputSchema.size());
    final TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).resumeSchema().buildSchema();
    {
        ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
        assertTrue(filter instanceof DynamicSchemaFilter);
        assertTrue(isProjected(filter, readerOutputSchema.metadata("a")));
        assertTrue(isProjected(filter, readerOutputSchema.metadata("m")));
        assertFalse(filter.isProjected("b"));
        final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
        final ProjectionFilter mapFilter = filter.projection(mapCol).mapFilter;
        assertTrue(mapFilter instanceof DynamicSchemaFilter);
        final TupleMetadata mapSchema = mapCol.tupleSchema();
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertFalse(mapFilter.isProjected("y"));
        assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
    }
    schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
    assertEquals(initVersion, schemaTracker.schemaVersion());
    // Scan output sent downstream
    assertTrue(schemaTracker.isResolved());
    assertEquals(targetSchema, schemaTracker.outputSchema());
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder)

Example 30 with ProjectionFilter

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

the class TestScanSchemaTrackerMaps method doTestSpecificMapWithSchema.

private void doTestSpecificMapWithSchema(ScanSchemaConfigBuilder builder, TupleMetadata targetSchema) {
    final ScanSchemaTracker schemaTracker = builder.build();
    assertTrue(schemaTracker.isResolved());
    final int initVersion = schemaTracker.schemaVersion();
    // Pretend the reader reads one of the map columns and discovers a new one.
    TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
    assertEquals(2, reader1InputSchema.size());
    final TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).resumeSchema().buildSchema();
    {
        ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
        assertTrue(filter instanceof DynamicSchemaFilter);
        assertTrue(isProjected(filter, readerOutputSchema.metadata("a")));
        assertTrue(isProjected(filter, readerOutputSchema.metadata("m")));
        assertFalse(filter.isProjected("b"));
        final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
        final ProjectionFilter mapFilter = filter.projection(mapCol).mapFilter;
        assertTrue(mapFilter instanceof DynamicSchemaFilter);
        final TupleMetadata mapSchema = mapCol.tupleSchema();
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertFalse(mapFilter.isProjected("y"));
        assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
    }
    schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
    assertEquals(initVersion, schemaTracker.schemaVersion());
    // Scan output sent downstream
    assertTrue(schemaTracker.isResolved());
    assertEquals(targetSchema, schemaTracker.outputSchema());
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder)

Aggregations

ProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter)42 EvfTest (org.apache.drill.categories.EvfTest)36 Test (org.junit.Test)36 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)35 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)33 BaseTest (org.apache.drill.test.BaseTest)24 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)13 SubOperatorTest (org.apache.drill.test.SubOperatorTest)12 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)7 RequestedTuple (org.apache.drill.exec.physical.resultSet.project.RequestedTuple)6 UnresolvedColumn (org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn)5 UserException (org.apache.drill.common.exceptions.UserException)3 DynamicTupleFilter (org.apache.drill.exec.physical.impl.scan.v3.schema.DynamicSchemaFilter.DynamicTupleFilter)3 ProjectionParseResult (org.apache.drill.exec.physical.impl.scan.v3.schema.ScanProjectionParser.ProjectionParseResult)2 RequestedColumn (org.apache.drill.exec.physical.resultSet.project.RequestedColumn)2 UnresolvedWildcardColumn (org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedWildcardColumn)1