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