use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanLevelProjection method testStrictProvidedSchemaWildcard.
/**
* Wildcard projection with a strict schema is the same as a non-strict
* schema, except that the projection type is different.
*/
@Test
public void testStrictProvidedSchemaWildcard() {
TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
providedSchema.setProperty(TupleMetadata.IS_STRICT_SCHEMA_PROP, Boolean.TRUE.toString());
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers(), providedSchema);
assertEquals(ScanProjectionType.STRICT_SCHEMA_WILDCARD, scanProj.projectionType());
assertEquals(2, scanProj.columns().size());
assertEquals("a", scanProj.columns().get(0).name());
assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumn);
assertEquals("b", scanProj.columns().get(1).name());
assertTrue(scanProj.columns().get(1) instanceof UnresolvedColumn);
// Make up a reader schema and test the projection set.
TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).add("c", MinorType.INT).buildSchema();
ProjectionFilter projSet = scanProj.readerProjection();
assertTrue(isProjected(projSet, readerSchema.metadata("a")));
assertTrue(isProjected(projSet, readerSchema.metadata("b")));
assertFalse(isProjected(projSet, readerSchema.metadata("c")));
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanLevelProjection method testWildcardAndColumns.
/**
* Can include both a wildcard and a column name. The Project
* operator will fill in the column, the scan framework just ignores
* the extra column.
*/
@Test
public void testWildcardAndColumns() {
ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(SchemaPath.DYNAMIC_STAR, "a"), ScanTestUtils.parsers());
assertTrue(scanProj.projectAll());
assertFalse(scanProj.isEmptyProjection());
assertEquals(2, scanProj.requestedCols().size());
assertEquals(1, scanProj.columns().size());
// Verify tuple projection
RequestedTuple outputProj = scanProj.rootProjection();
assertEquals(2, outputProj.projections().size());
assertNotNull(outputProj.get(SchemaPath.DYNAMIC_STAR));
assertTrue(outputProj.get(SchemaPath.DYNAMIC_STAR).isWildcard());
assertNotNull(outputProj.get("a"));
// Make up a reader schema and test the projection set.
TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).add("c", MinorType.INT).buildSchema();
ProjectionFilter projSet = scanProj.readerProjection();
assertTrue(isProjected(projSet, readerSchema.metadata("a")));
assertTrue(isProjected(projSet, readerSchema.metadata("c")));
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanLevelProjection method testMap.
/**
* Map projection occurs when a query contains project-list items with
* a dot, such as "a.b". We may not know the type of "b", but have
* just learned that "a" must be a map.
*/
@Test
public void testMap() {
// SELECT a.x, b.x, a.y, b.y, c
// We infer a and b are maps.
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a.x", "b.x", "a.y", "b.y", "c"), ScanTestUtils.parsers());
assertFalse(scanProj.projectAll());
assertFalse(scanProj.isEmptyProjection());
assertEquals(3, scanProj.columns().size());
assertEquals("a", scanProj.columns().get(0).name());
assertEquals("b", scanProj.columns().get(1).name());
assertEquals("c", scanProj.columns().get(2).name());
// Verify column type
assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumn);
// Inferred map structure
final RequestedColumn a = ((UnresolvedColumn) scanProj.columns().get(0)).element();
assertTrue(a.isTuple());
assertTrue(a.tuple().isProjected("x"));
assertTrue(a.tuple().isProjected("y"));
assertFalse(a.tuple().isProjected("z"));
final RequestedColumn c = ((UnresolvedColumn) scanProj.columns().get(2)).element();
assertTrue(c.isSimple());
// Verify tuple projection
RequestedTuple outputProj = scanProj.rootProjection();
assertEquals(3, outputProj.projections().size());
assertNotNull(outputProj.get("a"));
assertTrue(outputProj.get("a").isTuple());
// Make up a reader schema and test the projection set.
TupleMetadata readerSchema = new SchemaBuilder().addMap("a").add("x", MinorType.INT).add("y", MinorType.INT).resumeSchema().addMap("b").add("x", MinorType.INT).add("y", MinorType.INT).resumeSchema().add("c", MinorType.INT).add("d", MinorType.INT).buildSchema();
// Verify the projection set as if we were a reader. Note that the
// projection type is used here for testing; should not be used by
// an actual reader.
ProjectionFilter projSet = scanProj.readerProjection();
assertTrue(isProjected(projSet, readerSchema.metadata("a")));
assertTrue(isProjected(projSet, readerSchema.metadata("c")));
assertFalse(isProjected(projSet, readerSchema.metadata("d")));
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanLevelProjection method testProvidedSchemaWildcard.
@Test
public void testProvidedSchemaWildcard() {
TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers(), providedSchema);
assertEquals(ScanProjectionType.SCHEMA_WILDCARD, scanProj.projectionType());
assertEquals(2, scanProj.columns().size());
ColumnProjection aCol = scanProj.columns().get(0);
assertEquals("a", aCol.name());
assertTrue(aCol instanceof UnresolvedColumn);
assertSame(providedSchema.metadata("a"), ((UnresolvedColumn) aCol).metadata());
ColumnProjection bCol = scanProj.columns().get(1);
assertEquals("b", bCol.name());
assertTrue(bCol instanceof UnresolvedColumn);
assertSame(providedSchema.metadata("b"), ((UnresolvedColumn) bCol).metadata());
ProjectionFilter projSet = scanProj.readerProjection();
assertTrue(isProjected(projSet, providedSchema.metadata("a")));
assertTrue(isProjected(projSet, providedSchema.metadata("b")));
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestSchemaTrackerDefined method testDynamicDefinedSchema.
/**
* If a schema is defined, then the planner has combined the projection
* list with schema information to produce the final output schema
* at plan time. The planner might leave some columns as dynamic type:
* the schema (like projection) says which columns are wanted. But, like
* a full dynamic schema, the types may not be known.
*/
@Test
public void testDynamicDefinedSchema() {
// Simulate SELECT a, b, c ...
// With a plan-provided defined schema
final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder().projection(RowSetTestUtils.projectList("a", "b", "c"));
final TupleMetadata definedSchema = new SchemaBuilder().addDynamic("a").add("b", MinorType.BIGINT).add("c", MinorType.VARCHAR).buildSchema();
builder.definedSchema(definedSchema);
final ScanSchemaTracker schemaTracker = builder.build();
assertTrue(schemaTracker instanceof ProjectionSchemaTracker);
assertSame(ProjectionType.SOME, schemaTracker.projectionType());
assertFalse(schemaTracker.isResolved());
// Reader input schema is partially defined
final TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
assertEquals(definedSchema, reader1InputSchema);
ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
assertTrue(filter instanceof DynamicSchemaFilter);
// Pretend the reader dutifully provided two of the columns
TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
// Reader schema is now fully resolved
assertTrue(schemaTracker.isResolved());
final TupleMetadata reader2InputSchema = schemaTracker.readerInputSchema();
TupleMetadata expected = new SchemaBuilder().addAll(readerOutputSchema).add("c", MinorType.VARCHAR).build();
assertEquals(expected, reader2InputSchema);
// Pretend an class fills in the the missing columns
TupleMetadata missingColSchema = new SchemaBuilder().add("c", MinorType.VARCHAR).buildSchema();
schemaTracker.applyReaderSchema(missingColSchema, ERROR_CONTEXT);
// Final schema sent downstream
final TupleMetadata outputSchema = schemaTracker.outputSchema();
assertEquals(expected, outputSchema);
}
Aggregations