use of org.apache.drill.exec.physical.resultSet.project.RequestedTuple in project drill by apache.
the class ScanLevelProjection method buildReaderProjection.
private void buildReaderProjection() {
// Create the reader projection which includes either all columns
// (saw a wildcard) or just the unresolved columns (which excludes
// implicit columns.)
//
// Note that only the wildcard without schema can omit the output
// projection. With a schema, we want the schema columns (which may
// or may not correspond to reader columns.)
RequestedTuple rootProjection;
if (projectionType == ScanProjectionType.EMPTY) {
rootProjection = ImpliedTupleRequest.NO_MEMBERS;
} else if (projectionType != ScanProjectionType.EXPLICIT) {
rootProjection = ImpliedTupleRequest.ALL_MEMBERS;
} else {
List<RequestedColumn> outputProj = new ArrayList<>();
for (ColumnProjection col : outputCols) {
if (col instanceof AbstractUnresolvedColumn) {
outputProj.add(((AbstractUnresolvedColumn) col).element());
}
}
rootProjection = Projections.build(outputProj);
}
readerProjection = ProjectionFilter.providedSchemaFilter(rootProjection, readerSchema, errorContext);
}
use of org.apache.drill.exec.physical.resultSet.project.RequestedTuple in project drill by apache.
the class TestProjectionFilter method testProjectList.
@Test
public void testProjectList() {
RequestedTuple projSet = Projections.parse(RowSetTestUtils.projectList("a", "c", "m.a"));
ProjectionFilter filter = new DirectProjectionFilter(projSet, EmptyErrorContext.INSTANCE);
assertTrue(filter.isProjected("a"));
assertTrue(filter.projection(A_COL).isProjected);
assertFalse(filter.isProjected("b"));
assertFalse(filter.projection(B_COL).isProjected);
assertFalse(filter.isEmpty());
ProjResult result = filter.projection(MAP_COL);
assertTrue(result.isProjected);
ProjectionFilter child = result.mapFilter;
assertTrue(child.isProjected("a"));
assertFalse(child.isProjected("b"));
result = filter.projection(MAP_COL2);
assertFalse(result.isProjected);
assertSame(ProjectionFilter.PROJECT_NONE, result.mapFilter);
}
use of org.apache.drill.exec.physical.resultSet.project.RequestedTuple in project drill by apache.
the class TestScanLevelProjection method testArray.
/**
* Similar to maps, if the project list contains "a[1]" then we've learned that
* a is an array, but we don't know what type.
*/
@Test
public void testArray() {
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a[1]", "a[3]"), ScanTestUtils.parsers());
assertFalse(scanProj.projectAll());
assertFalse(scanProj.isEmptyProjection());
assertEquals(1, scanProj.columns().size());
assertEquals("a", scanProj.columns().get(0).name());
// Verify column type
assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumn);
// Map structure
final RequestedColumn a = ((UnresolvedColumn) scanProj.columns().get(0)).element();
assertTrue(a.isArray());
assertFalse(a.hasIndex(0));
assertTrue(a.hasIndex(1));
assertFalse(a.hasIndex(2));
assertTrue(a.hasIndex(3));
// Verify tuple projection
RequestedTuple outputProj = scanProj.rootProjection();
assertEquals(1, outputProj.projections().size());
assertNotNull(outputProj.get("a"));
assertTrue(outputProj.get("a").isArray());
// Make up a reader schema and test the projection set.
TupleMetadata readerSchema = new SchemaBuilder().addArray("a", MinorType.INT).add("c", MinorType.INT).buildSchema();
ProjectionFilter projSet = scanProj.readerProjection();
assertTrue(isProjected(projSet, readerSchema.metadata("a")));
assertFalse(isProjected(projSet, readerSchema.metadata("c")));
}
use of org.apache.drill.exec.physical.resultSet.project.RequestedTuple in project drill by apache.
the class TestScanLevelProjection method testWildcard.
/**
* Simulate a SELECT * query by passing "**" (Drill's internal representation
* of the wildcard) as a column name.
*/
@Test
public void testWildcard() {
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers());
assertTrue(scanProj.projectAll());
assertFalse(scanProj.isEmptyProjection());
assertEquals(1, scanProj.requestedCols().size());
assertTrue(scanProj.requestedCols().get(0).isDynamicStar());
assertEquals(1, scanProj.columns().size());
assertEquals(SchemaPath.DYNAMIC_STAR, scanProj.columns().get(0).name());
// Verify bindings
assertEquals(scanProj.columns().get(0).name(), scanProj.requestedCols().get(0).rootName());
// Verify column type
assertTrue(scanProj.columns().get(0) instanceof UnresolvedWildcardColumn);
// Verify tuple projection
RequestedTuple outputProj = scanProj.rootProjection();
assertEquals(1, outputProj.projections().size());
assertNotNull(outputProj.get(SchemaPath.DYNAMIC_STAR));
assertTrue(outputProj.get(SchemaPath.DYNAMIC_STAR).isWildcard());
// 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.project.RequestedTuple 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")));
}
Aggregations