use of org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver in project drill by apache.
the class TestSchemaTrackerEarlyReaderSchema method shadowImplicit.
/**
* If a reader column shadows an implicit column, then we treat the
* reader column as unprojected and log a warning (that warning is not
* tested here.)
*/
@Test
public void shadowImplicit() {
ProjectionSchemaTracker tracker = trackerFor(RowSetTestUtils.projectList("a", ScanTestUtils.FULLY_QUALIFIED_NAME_COL));
ImplicitColumnOptions options = new ImplicitColumnOptions().optionSet(fixture.getOptionManager());
ImplicitColumnResolver parser = new ImplicitColumnResolver(options, ERROR_CONTEXT);
parser.parse(tracker);
TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable(ScanTestUtils.FULLY_QUALIFIED_NAME_COL, MinorType.BIGINT).build();
tracker.applyEarlyReaderSchema(readerSchema);
TupleMetadata expected = new SchemaBuilder().add("a", MinorType.INT).add(ScanTestUtils.FULLY_QUALIFIED_NAME_COL, MinorType.VARCHAR).build();
assertEquals(expected, tracker.internalSchema().toSchema());
}
use of org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver in project drill by apache.
the class TestImplicitColumnResolver method testImplicitWithDefinedSchema.
@Test
public void testImplicitWithDefinedSchema() {
final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder().projection(RowSetTestUtils.projectList("a", "b", "c", ScanTestUtils.FILE_NAME_COL, ScanTestUtils.FILE_PATH_COL, ScanTestUtils.partitionColName(0), ScanTestUtils.partitionColName(2)));
final TupleMetadata definedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).add("c", MinorType.VARCHAR).add(ScanTestUtils.FILE_NAME_COL, MinorType.VARCHAR).add(ScanTestUtils.FILE_PATH_COL, MinorType.VARCHAR).addNullable(ScanTestUtils.partitionColName(0), MinorType.VARCHAR).addNullable(ScanTestUtils.partitionColName(2), MinorType.VARCHAR).buildSchema();
// With a defined schema, we have to explicitly mark implicit columns
// so the schema is independent of system/session options.
SchemaUtils.markImplicit(definedSchema.metadata(ScanTestUtils.FILE_NAME_COL), ColumnMetadata.IMPLICIT_FILENAME);
SchemaUtils.markImplicit(definedSchema.metadata(ScanTestUtils.FILE_PATH_COL), ScanTestUtils.FILE_PATH_COL);
SchemaUtils.markAsPartition(definedSchema.metadata(ScanTestUtils.partitionColName(0)), 0);
SchemaUtils.markAsPartition(definedSchema.metadata(ScanTestUtils.partitionColName(2)), 2);
builder.definedSchema(definedSchema);
final ScanSchemaTracker schemaTracker = builder.build();
assertTrue(schemaTracker instanceof SchemaBasedTracker);
assertTrue(schemaTracker.isResolved());
assertSame(ProjectionType.SOME, schemaTracker.projectionType());
ImplicitColumnOptions options = new ImplicitColumnOptions().optionSet(fixture.getOptionManager());
ImplicitColumnResolver parser = new ImplicitColumnResolver(options, ERROR_CONTEXT);
ParseResult result = parser.parse(schemaTracker);
assertEquals(4, result.columns().size());
TupleMetadata readerInputSchema = schemaTracker.readerInputSchema();
assertEquals(3, readerInputSchema.size());
assertEquals(definedSchema, schemaTracker.outputSchema());
}
Aggregations