Search in sources :

Example 1 with ImplicitColumnOptions

use of org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ImplicitColumnOptions 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());
}
Also used : ImplicitColumnOptions(org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ImplicitColumnOptions) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ImplicitColumnResolver(org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 2 with ImplicitColumnOptions

use of org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ImplicitColumnOptions 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());
}
Also used : ScanSchemaTracker(org.apache.drill.exec.physical.impl.scan.v3.schema.ScanSchemaTracker) SchemaBasedTracker(org.apache.drill.exec.physical.impl.scan.v3.schema.SchemaBasedTracker) ImplicitColumnOptions(org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ImplicitColumnOptions) ParseResult(org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ParseResult) ProjectionParseResult(org.apache.drill.exec.physical.impl.scan.v3.schema.ScanProjectionParser.ProjectionParseResult) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ScanSchemaConfigBuilder(org.apache.drill.exec.physical.impl.scan.v3.schema.ScanSchemaConfigBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) EvfTest(org.apache.drill.categories.EvfTest) Test(org.junit.Test)

Aggregations

EvfTest (org.apache.drill.categories.EvfTest)2 ImplicitColumnOptions (org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ImplicitColumnOptions)2 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)2 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)2 SubOperatorTest (org.apache.drill.test.SubOperatorTest)2 Test (org.junit.Test)2 ImplicitColumnResolver (org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver)1 ParseResult (org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ParseResult)1 ProjectionParseResult (org.apache.drill.exec.physical.impl.scan.v3.schema.ScanProjectionParser.ProjectionParseResult)1 ScanSchemaConfigBuilder (org.apache.drill.exec.physical.impl.scan.v3.schema.ScanSchemaConfigBuilder)1 ScanSchemaTracker (org.apache.drill.exec.physical.impl.scan.v3.schema.ScanSchemaTracker)1 SchemaBasedTracker (org.apache.drill.exec.physical.impl.scan.v3.schema.SchemaBasedTracker)1