use of org.apache.drill.exec.physical.resultSet.project.RequestedTuple 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.RequestedTuple in project drill by apache.
the class TestScanLevelProjection method testEmptyProjection.
/**
* Test an empty projection which occurs in a
* SELECT COUNT(*) query.
*/
@Test
public void testEmptyProjection() {
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(), ScanTestUtils.parsers());
assertFalse(scanProj.projectAll());
assertTrue(scanProj.isEmptyProjection());
assertEquals(0, scanProj.requestedCols().size());
// Verify tuple projection
RequestedTuple outputProj = scanProj.rootProjection();
assertEquals(0, outputProj.projections().size());
// Make up a reader schema and test the projection set.
TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
ProjectionFilter projSet = scanProj.readerProjection();
assertFalse(isProjected(projSet, readerSchema.metadata("a")));
}
use of org.apache.drill.exec.physical.resultSet.project.RequestedTuple in project drill by apache.
the class TestScanLevelProjection method testBasics.
/**
* Basic test: select a set of columns (a, b, c) when the
* data source has an early schema of (a, c, d). (a, c) are
* projected, (d) is null.
*/
@Test
public void testBasics() {
// Simulate SELECT a, b, c ...
// Build the projection plan and verify
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a", "b", "c"), ScanTestUtils.parsers());
assertFalse(scanProj.projectAll());
assertFalse(scanProj.isEmptyProjection());
assertEquals(3, scanProj.requestedCols().size());
assertEquals("a", scanProj.requestedCols().get(0).rootName());
assertEquals("b", scanProj.requestedCols().get(1).rootName());
assertEquals("c", scanProj.requestedCols().get(2).rootName());
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);
// Verify tuple projection
RequestedTuple outputProj = scanProj.rootProjection();
assertEquals(3, outputProj.projections().size());
assertNotNull(outputProj.get("a"));
assertTrue(outputProj.get("a").isSimple());
// Make up a reader schema and test the projection set.
TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.INT).add("c", MinorType.INT).add("d", MinorType.INT).buildSchema();
ProjectionFilter projSet = scanProj.readerProjection();
assertTrue(isProjected(projSet, readerSchema.metadata("a")));
assertFalse(isProjected(projSet, readerSchema.metadata("d")));
}
use of org.apache.drill.exec.physical.resultSet.project.RequestedTuple in project drill by apache.
the class TestResultSetLoaderProjection method setupProvidedSchema.
// Setup to test the various project/provided schema cases in
// ProjectionFilter, especially CompoundProjectionFilter
public ResultSetLoader setupProvidedSchema(boolean isStrict, List<SchemaPath> selection) {
TupleMetadata schema = new SchemaBuilder().addMap("m1").add("a", MinorType.INT).add("b", MinorType.INT).resumeSchema().addMap("m2").add("c", MinorType.INT).add("d", MinorType.INT).resumeSchema().addMap("m3").add("e", MinorType.INT).add("f", MinorType.INT).resumeSchema().buildSchema();
// Provided schema: disjoint set of above.
TupleMetadata providedSchema = new SchemaBuilder().addMap(// Same
"m1").add("a", MinorType.INT).add("b", MinorType.INT).add("z", // Add a column
MinorType.INT).resumeSchema().addMap(// Omit c
"m2").add("d", MinorType.INT).resumeSchema().addMap(// Add m4
"m4").add("g", MinorType.INT).add("h", MinorType.INT).resumeSchema().build();
if (isStrict) {
SchemaUtils.markStrict(providedSchema);
}
RequestedTuple proj = Projections.parse(selection);
CustomErrorContext errorContext = new EmptyErrorContext();
ProjectionFilter projectionFilter = ProjectionFilter.providedSchemaFilter(proj, providedSchema, errorContext);
ResultSetOptions options = new ResultSetOptionBuilder().projectionFilter(projectionFilter).readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
// Write a couple of rows.
rsLoader.startBatch();
RowSetLoader rootWriter = rsLoader.writer();
rootWriter.start();
rootWriter.addRow(mapValue(1, 2), mapValue(3, 4), mapValue(5, 6)).addRow(mapValue(11, 12), mapValue(13, 14), mapValue(15, 16));
return rsLoader;
}
use of org.apache.drill.exec.physical.resultSet.project.RequestedTuple in project drill by apache.
the class TestProjectionFilter method testGenericMap.
@Test
public void testGenericMap() {
RequestedTuple projSet = Projections.parse(RowSetTestUtils.projectList("a", "m"));
ProjectionFilter filter = new DirectProjectionFilter(projSet, EmptyErrorContext.INSTANCE);
assertTrue(filter.isProjected("a"));
ProjResult result = filter.projection(MAP_COL);
assertTrue(result.isProjected);
assertSame(ProjectionFilter.PROJECT_ALL, result.mapFilter);
}
Aggregations