use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanSchemaTrackerMaps method doTestMapDefinedSchema.
private void doTestMapDefinedSchema(ScanSchemaConfigBuilder builder, TupleMetadata targetSchema) {
final ScanSchemaTracker schemaTracker = builder.build();
assertTrue(schemaTracker.isResolved());
// Pretend the reader reads one of the map columns and discovers a new one.
TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
assertEquals(targetSchema, reader1InputSchema);
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);
assertFalse(filter.isEmpty());
assertTrue(isProjected(filter, readerOutputSchema.metadata("a")));
assertTrue(isProjected(filter, readerOutputSchema.metadata("m")));
assertFalse(filter.isProjected("b"));
assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(filter, "w").mapFilter);
final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
final ProjectionFilter mapFilter = filter.projection(mapCol).mapFilter;
assertTrue(mapFilter instanceof DynamicSchemaFilter);
final TupleMetadata mapSchema = mapCol.tupleSchema();
assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
assertTrue(mapFilter.isProjected("y"));
assertFalse(mapFilter.isProjected("z"));
assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
}
schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
// Scan output schema is now resolved.
assertTrue(schemaTracker.isResolved());
assertEquals(targetSchema, schemaTracker.outputSchema());
// A second reader gets a strict filter for the row and map.
TupleMetadata reader2InputSchema = schemaTracker.readerInputSchema();
assertEquals(targetSchema, 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");
final ProjectionFilter mapFilter = filter.projection(mapCol).mapFilter;
assertTrue(mapFilter instanceof DynamicSchemaFilter);
final TupleMetadata mapSchema = mapCol.tupleSchema();
assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
assertFalse(mapFilter.isProjected("w"));
assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
}
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanSchemaTrackerMaps method testSpecificMapWithLenientProvidedSchema.
/**
* Test a specific map column ({@code m.x}) with a lenient
* provided schema. The schema can include columns other than
* the specific one, but only the specific one will be projected.
* Note that the projection list, not the provided schema, constrains
* projection in this case.
*/
@Test
public void testSpecificMapWithLenientProvidedSchema() {
final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder().projection(RowSetTestUtils.projectList("a", "m.x"));
final TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).add("y", MinorType.VARCHAR).resumeSchema().buildSchema();
builder.providedSchema(providedSchema);
final ScanSchemaTracker schemaTracker = builder.build();
assertTrue(schemaTracker.isResolved());
final int initVersion = schemaTracker.schemaVersion();
// 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"));
assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(filter, "w").mapFilter);
final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
final ProjectionFilter mapFilter = filter.projection(mapCol).mapFilter;
assertTrue(mapFilter instanceof DynamicSchemaFilter);
final TupleMetadata mapSchema = mapCol.tupleSchema();
assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
assertFalse(mapFilter.isProjected("y"));
assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
}
schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
assertEquals(initVersion, schemaTracker.schemaVersion());
// 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 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 in project drill by apache.
the class TestScanSchemaTrackerMaps method doTestGenericMapWithSchema.
private void doTestGenericMapWithSchema(ScanSchemaConfigBuilder builder, TupleMetadata targetSchema) {
final ScanSchemaTracker schemaTracker = builder.build();
assertTrue(schemaTracker.isResolved());
final int initVersion = schemaTracker.schemaVersion();
// 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;
assertTrue(mapFilter instanceof DynamicSchemaFilter);
final TupleMetadata mapSchema = mapCol.tupleSchema();
assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
assertFalse(mapFilter.isProjected("y"));
assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
}
schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
assertEquals(initVersion, schemaTracker.schemaVersion());
// Scan output sent downstream
assertTrue(schemaTracker.isResolved());
assertEquals(targetSchema, schemaTracker.outputSchema());
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanSchemaTrackerMaps method doTestSpecificMapWithSchema.
private void doTestSpecificMapWithSchema(ScanSchemaConfigBuilder builder, TupleMetadata targetSchema) {
final ScanSchemaTracker schemaTracker = builder.build();
assertTrue(schemaTracker.isResolved());
final int initVersion = schemaTracker.schemaVersion();
// 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;
assertTrue(mapFilter instanceof DynamicSchemaFilter);
final TupleMetadata mapSchema = mapCol.tupleSchema();
assertTrue(isProjected(mapFilter, mapSchema.metadata("x")));
assertFalse(mapFilter.isProjected("y"));
assertSame(ProjectionFilter.PROJECT_NONE, mapProjection(mapFilter, "w").mapFilter);
}
schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
assertEquals(initVersion, schemaTracker.schemaVersion());
// Scan output sent downstream
assertTrue(schemaTracker.isResolved());
assertEquals(targetSchema, schemaTracker.outputSchema());
}
Aggregations