Search in sources :

Example 1 with TypeProjectionFilter

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

the class TestProjectionFilter method testTypeFilter.

@Test
public void testTypeFilter() {
    TupleMetadata schema = new SchemaBuilder().add(A_COL.copy()).add(B_COL.copy()).addMap("m").add("a", MinorType.INT).resumeSchema().build();
    ProjectionFilter filter = new TypeProjectionFilter(schema, EmptyErrorContext.INSTANCE);
    assertFalse(filter.isEmpty());
    assertTrue(filter.isProjected("a"));
    assertTrue(filter.projection(A_COL).isProjected);
    assertTrue(filter.isProjected("b"));
    assertTrue(filter.projection(B_COL).isProjected);
    assertTrue(filter.isProjected("c"));
    assertTrue(filter.projection(MetadataUtils.newScalar("c", Types.required(MinorType.BIGINT))).isProjected);
    ColumnMetadata typeConflict = MetadataUtils.newScalar("a", Types.required(MinorType.BIGINT));
    try {
        filter.projection(typeConflict);
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("conflict"));
    }
    ColumnMetadata modeConflict = MetadataUtils.newScalar("a", Types.optional(MinorType.INT));
    try {
        filter.projection(modeConflict);
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("conflict"));
    }
    ProjResult result = filter.projection(MAP_COL);
    assertTrue(result.isProjected);
    ProjectionFilter child = result.mapFilter;
    assertTrue(child.isProjected("a"));
    assertTrue(child.isProjected("b"));
    result = filter.projection(MAP_COL2);
    assertTrue(result.isProjected);
    assertSame(ProjectionFilter.PROJECT_ALL, result.mapFilter);
    try {
        ColumnMetadata aMap = MetadataUtils.newMap("a", new TupleSchema());
        filter.projection(aMap);
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("type conflict"));
    }
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) 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) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) UserException(org.apache.drill.common.exceptions.UserException) TypeProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.TypeProjectionFilter) ProjResult(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest)

Aggregations

UserException (org.apache.drill.common.exceptions.UserException)1 CompoundProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.CompoundProjectionFilter)1 DirectProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.DirectProjectionFilter)1 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)1 SchemaProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.SchemaProjectionFilter)1 TypeProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.TypeProjectionFilter)1 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)1 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)1 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)1 TupleSchema (org.apache.drill.exec.record.metadata.TupleSchema)1 BaseTest (org.apache.drill.test.BaseTest)1 Test (org.junit.Test)1