use of org.apache.drill.exec.physical.impl.scan.v3.schema.ScanSchemaTracker 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