use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanSchemaTrackerMaps method testSpecificMapSubset.
@Test
public void testSpecificMapSubset() {
final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder().projection(RowSetTestUtils.projectList("a", "m.x", "m.y"));
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();
{
final ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
assertTrue(filter instanceof DynamicSchemaFilter);
final ColumnMetadata mapCol = readerOutputSchema.metadata("m");
final ProjectionFilter mapFilter = filter.projection(mapCol).mapFilter;
assertTrue(mapFilter instanceof DynamicSchemaFilter);
}
schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
// Scan output schema is not yet resolved.
assertFalse(schemaTracker.isResolved());
// Missing columns provided
final TupleMetadata missingCols = schemaTracker.missingColumns(readerOutputSchema);
final TupleMetadata expectedMissingCols = new SchemaBuilder().addMap("m").addDynamic("y").resumeSchema().buildSchema();
assertEquals(expectedMissingCols, missingCols);
final TupleMetadata missingColsOutput = new SchemaBuilder().addMap("m").addNullable("y", MinorType.VARCHAR).resumeSchema().buildSchema();
schemaTracker.resolveMissingCols(missingColsOutput);
// Schema is now resolved
assertTrue(schemaTracker.isResolved());
final TupleMetadata expected = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).addNullable("y", MinorType.VARCHAR).resumeSchema().buildSchema();
assertEquals(expected, schemaTracker.outputSchema());
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanSchemaTrackerMaps method testMapWithWildcardNoSchemaChange.
@Test
public void testMapWithWildcardNoSchemaChange() {
final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder();
builder.allowSchemaChange(false);
final ScanSchemaTracker schemaTracker = builder.build();
assertFalse(schemaTracker.isResolved());
// Pretend the reader discovers that m is a map.
TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
assertTrue(reader1InputSchema.isEmpty());
final TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).add("y", MinorType.VARCHAR).resumeSchema().buildSchema();
{
final ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
assertSame(ProjectionFilter.PROJECT_ALL, filter);
assertFalse(filter.isEmpty());
}
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);
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(isProjected(mapFilter, mapSchema.metadata("y")));
assertFalse(mapFilter.isProjected("z"));
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 testMapWithWildcard.
@Test
public void testMapWithWildcard() {
final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder();
final ScanSchemaTracker schemaTracker = builder.build();
assertFalse(schemaTracker.isResolved());
// Pretend the reader discovers that m is a map.
TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
assertTrue(reader1InputSchema.isEmpty());
final TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("x", MinorType.BIGINT).add("y", MinorType.VARCHAR).resumeSchema().buildSchema();
{
final ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
assertSame(ProjectionFilter.PROJECT_ALL, filter);
assertFalse(filter.isEmpty());
}
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);
assertFalse(filter.isEmpty());
assertTrue(isProjected(filter, readerOutputSchema.metadata("a")));
assertTrue(isProjected(filter, readerOutputSchema.metadata("m")));
assertTrue(filter.isProjected("b"));
assertSame(ProjectionFilter.PROJECT_ALL, 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(isProjected(mapFilter, mapSchema.metadata("y")));
assertTrue(mapFilter.isProjected("z"));
assertSame(ProjectionFilter.PROJECT_ALL, mapProjection(mapFilter, "w").mapFilter);
}
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanSchemaTrackerMaps method testGenericMapWithDynamicSchema.
@Test
public void testGenericMapWithDynamicSchema() {
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());
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;
assertSame(ProjectionFilter.PROJECT_ALL, mapFilter);
}
schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
assertTrue(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 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