use of org.apache.drill.exec.physical.resultSet.project.RequestedColumn 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.RequestedColumn 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.project.RequestedColumn in project drill by apache.
the class ExplicitSchemaProjection method resolveMapMembers.
/**
* A child column of a map is not projected. Recurse to determine the full
* set of nullable child columns.
*
* @param outputTuple projected tuple being built
* @param col the map column which was projected
* @return a list of null markers for the requested children
*/
private ResolvedColumn resolveMapMembers(ResolvedTuple outputTuple, RequestedColumn col) {
ResolvedMapColumn mapCol = new ResolvedMapColumn(outputTuple, col.name());
ResolvedTuple members = mapCol.members();
for (RequestedColumn child : col.tuple().projections()) {
if (child.isTuple()) {
members.add(resolveMapMembers(members, child));
} else {
members.add(outputTuple.nullBuilder.add(child.name()));
}
}
return mapCol;
}
use of org.apache.drill.exec.physical.resultSet.project.RequestedColumn in project drill by apache.
the class ScanLevelProjection method doParse.
private void doParse() {
outputProjection = Projections.parse(projectionList);
switch(outputProjection.type()) {
case ALL:
includesWildcard = true;
projectionType = ScanProjectionType.WILDCARD;
break;
case NONE:
projectionType = ScanProjectionType.EMPTY;
break;
default:
projectionType = ScanProjectionType.EXPLICIT;
break;
}
for (ScanProjectionParser parser : parsers) {
parser.bind(this);
}
// Process projected columns.
for (RequestedColumn inCol : outputProjection.projections()) {
if (inCol.isWildcard()) {
mapWildcard(inCol);
} else {
mapColumn(inCol);
}
}
verify();
for (ScanProjectionParser parser : parsers) {
parser.build();
}
buildReaderProjection();
}
Aggregations