Search in sources :

Example 36 with ProjectionFilter

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

the class TestScanSchemaTrackerMaps method testDynamicMapWithDefinedSchema.

@Test
public void testDynamicMapWithDefinedSchema() {
    final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder().projection(RowSetTestUtils.projectList("a", "m"));
    final TupleMetadata definedSchema = new SchemaBuilder().add("a", MinorType.INT).addDynamic("m").buildSchema();
    definedSchema.setBooleanProperty(TupleMetadata.IS_STRICT_SCHEMA_PROP, true);
    builder.definedSchema(definedSchema);
    final ScanSchemaTracker schemaTracker = builder.build();
    assertFalse(schemaTracker.isResolved());
    // 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;
        assertSame(ProjectionFilter.PROJECT_ALL, mapFilter);
        final TupleMetadata mapSchema = mapCol.tupleSchema();
        assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
        assertTrue(mapFilter.isProjected("y"));
        assertSame(ProjectionFilter.PROJECT_ALL, mapProjection(mapFilter, "w").mapFilter);
    }
    schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
    // 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 37 with ProjectionFilter

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

the class TestDynamicSchemaFilter method testProjectList.

@Test
public void testProjectList() {
    ProjectionParseResult parseResult = ScanProjectionParser.parse(RowSetTestUtils.projectList("a", "c", "m", "special"));
    ProjectionFilter filter = new DynamicTupleFilter(parseResult.dynamicSchema, EmptyErrorContext.INSTANCE);
    assertFalse(filter.isEmpty());
    assertTrue(filter.isProjected(A_COL.name()));
    ProjResult result = filter.projection(A_COL);
    assertTrue(result.isProjected);
    assertNotNull(result.projection);
    assertTrue(result.projection.isDynamic());
    assertEquals(A_COL.name(), result.projection.name());
    assertFalse(filter.isProjected(B_COL.name()));
    result = filter.projection(B_COL);
    assertFalse(result.isProjected);
    assertTrue(filter.isProjected(MAP_COL.name()));
    result = filter.projection(MAP_COL);
    assertTrue(result.isProjected);
    assertNotNull(result.projection);
    assertTrue(result.projection.isDynamic());
    assertEquals(MAP_COL.name(), result.projection.name());
    assertSame(ProjectionFilter.PROJECT_ALL, result.mapFilter);
    assertTrue(filter.isProjected(SPECIAL_COLUMN.name()));
    result = filter.projection(SPECIAL_COLUMN);
    assertTrue(result.isProjected);
    assertNotNull(result.projection);
    assertTrue(result.projection.isDynamic());
    assertEquals(SPECIAL_COLUMN.name(), result.projection.name());
    assertFalse(filter.isProjected(SPECIAL_COLUMN2.name()));
    result = filter.projection(SPECIAL_COLUMN2);
    assertFalse(result.isProjected);
}
Also used : ProjectionParseResult(org.apache.drill.exec.physical.impl.scan.v3.schema.ScanProjectionParser.ProjectionParseResult) 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 38 with ProjectionFilter

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

the class TestDynamicSchemaFilter method testEmptyProjectList.

@Test
public void testEmptyProjectList() {
    ProjectionFilter filter = ProjectionFilter.PROJECT_NONE;
    assertTrue(filter.isEmpty());
    assertFalse(filter.isProjected(A_COL.name()));
    ProjResult result = filter.projection(A_COL);
    assertFalse(result.isProjected);
    assertFalse(filter.isProjected(MAP_COL.name()));
    result = filter.projection(MAP_COL);
    assertFalse(result.isProjected);
    assertSame(ProjectionFilter.PROJECT_NONE, result.mapFilter);
    assertFalse(filter.isProjected(SPECIAL_COLUMN.name()));
    result = filter.projection(SPECIAL_COLUMN);
    assertFalse(result.isProjected);
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) 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 39 with ProjectionFilter

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

the class TestDynamicSchemaFilter method testProjectAll.

@Test
public void testProjectAll() {
    ProjectionFilter filter = ProjectionFilter.PROJECT_ALL;
    assertFalse(filter.isEmpty());
    assertTrue(filter.isProjected(A_COL.name()));
    ProjResult result = filter.projection(A_COL);
    assertTrue(result.isProjected);
    assertNull(result.projection);
    assertTrue(filter.isProjected(MAP_COL.name()));
    result = filter.projection(MAP_COL);
    assertTrue(result.isProjected);
    assertNull(result.projection);
    assertSame(ProjectionFilter.PROJECT_ALL, result.mapFilter);
    // "Special" columns are projected only by name, but rely on
    // a property in the column itself, so give inconsistent answers
    // from the filter.
    assertTrue(filter.isProjected(SPECIAL_COLUMN.name()));
    result = filter.projection(SPECIAL_COLUMN);
    assertFalse(result.isProjected);
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) 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 40 with ProjectionFilter

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

the class TestSchemaTrackerProjection method testEmpty.

@Test
public void testEmpty() {
    ProjectionSchemaTracker tracker = schemaTracker(Collections.emptyList());
    assertTrue(tracker.isResolved());
    assertEquals(1, tracker.schemaVersion());
    assertSame(ScanSchemaTracker.ProjectionType.NONE, tracker.projectionType());
    assertTrue(tracker.internalSchema().toSchema().isEmpty());
    ProjectionFilter filter = tracker.projectionFilter(ERROR_CONTEXT);
    assertSame(ProjectionFilter.PROJECT_NONE, filter);
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest) EvfTest(org.apache.drill.categories.EvfTest)

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