Search in sources :

Example 6 with ProjResult

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

the class TestProjectionFilter method testCompoundFilterMixed1.

@Test
public void testCompoundFilterMixed1() {
    ProjectionFilter filter = new CompoundProjectionFilter(ProjectionFilter.PROJECT_ALL, ProjectionFilter.PROJECT_NONE);
    assertFalse(filter.isProjected("a"));
    assertFalse(filter.projection(A_COL).isProjected);
    assertTrue(filter.isEmpty());
    ProjResult result = filter.projection(MAP_COL);
    assertFalse(result.isProjected);
    assertSame(ProjectionFilter.PROJECT_NONE, result.mapFilter);
}
Also used : SchemaProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.SchemaProjectionFilter) TypeProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.TypeProjectionFilter) DirectProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.DirectProjectionFilter) CompoundProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.CompoundProjectionFilter) ProjResult(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult) CompoundProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.CompoundProjectionFilter) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest)

Example 7 with ProjResult

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

the class TestDynamicSchemaFilter method testMapProjectList.

@Test
public void testMapProjectList() {
    ProjectionParseResult parseResult = ScanProjectionParser.parse(RowSetTestUtils.projectList("m.x"));
    ProjectionFilter filter = new DynamicTupleFilter(parseResult.dynamicSchema, EmptyErrorContext.INSTANCE);
    assertFalse(filter.isEmpty());
    assertTrue(filter.isProjected(MAP_COL.name()));
    ProjResult result = filter.projection(MAP_COL);
    assertTrue(result.isProjected);
    assertNotNull(result.projection);
    assertTrue(result.projection.isDynamic());
    assertEquals(MAP_COL.name(), result.projection.name());
    assertTrue(result.mapFilter instanceof DynamicTupleFilter);
    ProjectionFilter mapFilter = result.mapFilter;
    ColumnMetadata x_col = MAP_COL.tupleSchema().metadata("x");
    assertTrue(mapFilter.isProjected("x"));
    result = mapFilter.projection(x_col);
    assertTrue(result.isProjected);
    assertNotNull(result.projection);
    assertTrue(result.projection.isDynamic());
    assertEquals(x_col.name(), result.projection.name());
    ColumnMetadata y_col = MAP_COL.tupleSchema().metadata("y");
    assertFalse(mapFilter.isProjected("y"));
    result = mapFilter.projection(y_col);
    assertFalse(result.isProjected);
}
Also used : ProjectionParseResult(org.apache.drill.exec.physical.impl.scan.v3.schema.ScanProjectionParser.ProjectionParseResult) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) DynamicTupleFilter(org.apache.drill.exec.physical.impl.scan.v3.schema.DynamicSchemaFilter.DynamicTupleFilter) 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 8 with ProjResult

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

the class TestScanSchemaTrackerMaps method doTestGenericMap.

private void doTestGenericMap(ScanSchemaConfigBuilder builder, boolean isAll) {
    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).add("y", MinorType.VARCHAR).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;
        if (isAll) {
            assertSame(ProjectionFilter.PROJECT_ALL, mapFilter);
        } else {
            assertTrue(mapFilter instanceof DynamicSchemaFilter);
        }
        final TupleMetadata mapSchema = mapCol.tupleSchema();
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertTrue(isProjected(mapFilter, mapSchema.metadata("y")));
        assertTrue(mapFilter.isProjected("z"));
        assertSame(ProjectionFilter.PROJECT_ALL, 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);
    {
        final 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 TupleMetadata mapSchema = readerOutputSchema.metadata("m").tupleSchema();
        ProjResult mapResult = filter.projection(readerOutputSchema.metadata("m"));
        assertTrue(mapResult.isProjected);
        ProjectionFilter mapFilter = mapResult.mapFilter;
        assertTrue(mapFilter instanceof DynamicSchemaFilter);
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertTrue(isProjected(mapFilter, mapSchema.metadata("y")));
        assertTrue(mapFilter.isProjected("z"));
        assertSame(ProjectionFilter.PROJECT_ALL, mapFilter.projection(MetadataUtils.newMap("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)

Example 9 with ProjResult

use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult 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 10 with ProjResult

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

the class TestScanSchemaTrackerMaps method testTwoLevelGenericMap.

@Test
public void testTwoLevelGenericMap() {
    final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder().projection(RowSetTestUtils.projectList("a", "m"));
    final ScanSchemaTracker schemaTracker = builder.build();
    // Pretend the reader discovers that m is a map.
    final TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
    assertEquals(2, reader1InputSchema.size());
    final TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).add("y", MinorType.VARCHAR).addMap("m2").add("p", MinorType.BIGINT).add("q", MinorType.VARCHAR).resumeMap().resumeSchema().buildSchema();
    {
        final ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
        ProjResult result = filter.projection(MetadataUtils.newMap("m"));
        assertTrue(result.isProjected);
        final ProjectionFilter map1Filter = result.mapFilter;
        assertSame(ProjectionFilter.PROJECT_ALL, map1Filter);
        result = map1Filter.projection(MetadataUtils.newMap("m2"));
        assertTrue(result.isProjected);
        assertSame(ProjectionFilter.PROJECT_ALL, result.mapFilter);
    }
    schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
    // Scan output schema is now resolved.
    assertTrue(schemaTracker.isResolved());
    assertEquals(readerOutputSchema, schemaTracker.outputSchema());
    // A second reader gets a strict filter for the row, but a
    // project-all filter for the map.
    TupleMetadata reader2InputSchema = schemaTracker.readerInputSchema();
    assertEquals(readerOutputSchema, reader2InputSchema);
    {
        final ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
        assertTrue(filter instanceof DynamicSchemaFilter);
        final ProjectionFilter map1Filter = mapProjection(filter, "m").mapFilter;
        assertTrue(map1Filter instanceof DynamicSchemaFilter);
        assertTrue(map1Filter.isProjected("z"));
        final ProjectionFilter map2Filter = mapProjection(map1Filter, "m2").mapFilter;
        assertTrue(map2Filter instanceof DynamicSchemaFilter);
        assertTrue(map2Filter.isProjected("r"));
    }
    final TupleMetadata reader2OutputSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).add("y", MinorType.VARCHAR).addMap("m2").add("p", MinorType.BIGINT).add("q", MinorType.VARCHAR).add("r", MinorType.INT).resumeMap().add("z", MinorType.VARCHAR).resumeSchema().buildSchema();
    schemaTracker.applyReaderSchema(reader2OutputSchema, ERROR_CONTEXT);
    assertEquals(reader2OutputSchema, schemaTracker.outputSchema());
}
Also used : 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)

Aggregations

ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)22 BaseTest (org.apache.drill.test.BaseTest)17 Test (org.junit.Test)17 CompoundProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.CompoundProjectionFilter)11 DirectProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.DirectProjectionFilter)11 SchemaProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.SchemaProjectionFilter)11 TypeProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.TypeProjectionFilter)11 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)10 ProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter)7 EvfTest (org.apache.drill.categories.EvfTest)6 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)6 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)6 ListVectorState (org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState)4 RepeatedListVectorState (org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState)4 OffsetVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState)4 SimpleVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.SimpleVectorState)4 MapVectorState (org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState)4 UnionVectorState (org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState)4 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)3 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)3