use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class ScanSchemaResolver method mergeWithConcrete.
/**
* Merge an incoming column with an existing resolved column. Non-map columns
* must match. Maps are merged recursively.
*/
private void mergeWithConcrete(ColumnMetadata existing, ColumnMetadata revised) {
SchemaUtils.verifyConsistency(existing, revised, source, errorContext);
if (existing.isMap()) {
ProjectionFilter filter = new DynamicTupleFilter(existing.tupleSchema(), allowMapAdditions, errorContext, source);
expandMapProjection(existing.tupleSchema(), filter, revised.tupleSchema());
}
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanLevelProjection method testProvidedSchemaTypeMismatch.
@Test
public void testProvidedSchemaTypeMismatch() {
TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers(), providedSchema);
// Make up a reader schema and test the projection set.
// Schema deliberately conflicts with the provided schema.
TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.INT).add("c", MinorType.INT).buildSchema();
ProjectionFilter projSet = scanProj.readerProjection();
assertTrue(projSet.isProjected("b"));
try {
projSet.projection(readerSchema.metadata("b"));
fail();
} catch (UserException e) {
// Expected
}
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.
the class TestScanLevelProjection method testProvidedSchemaModeMismatch.
@Test
public void testProvidedSchemaModeMismatch() {
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);
// Make up a reader schema and test the projection set.
// Mode deliberately conflicts with the provided schema
TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("b", MinorType.INT).add("c", MinorType.INT).buildSchema();
ProjectionFilter projSet = scanProj.readerProjection();
assertTrue(projSet.isProjected("b"));
try {
isProjected(projSet, readerSchema.metadata("b"));
fail();
} catch (UserException e) {
// Expected
}
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter 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.impl.ProjectionFilter 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")));
}
Aggregations