use of org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn 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.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn 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.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn 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.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn 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.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn in project drill by apache.
the class TestImplicitColumnParser method testShadowed.
/**
* Verify that names that look like metadata columns, but appear
* to be maps or arrays, are not interpreted as metadata. That is,
* the projected table map or array "shadows" the metadata column.
*/
@Test
public void testShadowed() {
Path filePath = new Path("hdfs:///w/x/y/z.csv");
ImplicitColumnManager implictColManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(ScanTestUtils.FILE_NAME_COL + ".a", ScanTestUtils.FILE_PATH_COL + "[0]", ScanTestUtils.partitionColName(0) + ".b", ScanTestUtils.partitionColName(1) + "[0]", ScanTestUtils.SUFFIX_COL), Lists.newArrayList(implictColManager.projectionParser()));
List<ColumnProjection> cols = scanProj.columns();
assertEquals(5, cols.size());
for (int i = 0; i < 4; i++) {
assertTrue(scanProj.columns().get(i) instanceof UnresolvedColumn);
}
assertTrue(scanProj.columns().get(4) instanceof FileMetadataColumn);
}
Aggregations