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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations