Search in sources :

Example 6 with ParseResult

use of org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ParseResult in project drill by apache.

the class TestImplicitColumnResolver method testFileImplicitColumnSelection.

/**
 * Test including file implicit columns in the project list.
 */
@Test
public void testFileImplicitColumnSelection() {
    // Simulate SELECT a, fqn, filEPath, filename, suffix ...
    ParserFixture parseFixture = new ParserFixture(RowSetTestUtils.projectList("a", ScanTestUtils.FULLY_QUALIFIED_NAME_COL, // Sic, to test case sensitivity
    "filEPath", ScanTestUtils.FILE_NAME_COL, ScanTestUtils.SUFFIX_COL));
    ParseResult result = parseFixture.parseImplicit();
    assertFalse(result.isMetadataScan());
    assertEquals(4, result.columns().size());
    TupleMetadata expected = new SchemaBuilder().add(ScanTestUtils.FULLY_QUALIFIED_NAME_COL, MinorType.VARCHAR).add("filEPath", MinorType.VARCHAR).add(ScanTestUtils.FILE_NAME_COL, MinorType.VARCHAR).add(ScanTestUtils.SUFFIX_COL, MinorType.VARCHAR).build();
    assertEquals(expected, result.schema());
    List<ColumnHandle> cols = parseFixture.tracker.internalSchema().columns();
    assertFalse(isImplicit(cols, 0));
    assertTrue(isImplicit(cols, 1));
    assertTrue(isImplicit(cols, 2));
    assertTrue(isImplicit(cols, 3));
    assertTrue(isImplicit(cols, 4));
}
Also used : ColumnHandle(org.apache.drill.exec.physical.impl.scan.v3.schema.MutableTupleSchema.ColumnHandle) 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) SubOperatorTest(org.apache.drill.test.SubOperatorTest) EvfTest(org.apache.drill.categories.EvfTest) Test(org.junit.Test)

Example 7 with ParseResult

use of org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ParseResult in project drill by apache.

the class TestImplicitColumnResolver method testInternalImplicitColumnSelection.

/**
 * Test including internal implicit columns in the project list.
 * @throws IOException
 */
@Test
public void testInternalImplicitColumnSelection() throws IOException {
    // Simulate SELECT lmt, $project_metadata$", rgi, rgs, rgl ...
    Configuration conf = new Configuration();
    conf.set(FileSystem.FS_DEFAULT_NAME_KEY, FileSystem.DEFAULT_FS);
    DrillFileSystem dfs = new DrillFileSystem(conf);
    ParserFixture parseFixture = new ParserFixture(RowSetTestUtils.projectList("a", ScanTestUtils.LAST_MODIFIED_TIME_COL, ScanTestUtils.PROJECT_METADATA_COL, ScanTestUtils.ROW_GROUP_INDEX_COL, ScanTestUtils.ROW_GROUP_START_COL, ScanTestUtils.ROW_GROUP_LENGTH_COL));
    parseFixture.options.dfs(dfs);
    ParseResult result = parseFixture.parseImplicit();
    assertTrue(result.isMetadataScan());
    assertEquals(5, result.columns().size());
    TupleMetadata expected = new SchemaBuilder().add(ScanTestUtils.LAST_MODIFIED_TIME_COL, MinorType.VARCHAR).addNullable(ScanTestUtils.PROJECT_METADATA_COL, MinorType.VARCHAR).add(ScanTestUtils.ROW_GROUP_INDEX_COL, MinorType.VARCHAR).add(ScanTestUtils.ROW_GROUP_START_COL, MinorType.VARCHAR).add(ScanTestUtils.ROW_GROUP_LENGTH_COL, MinorType.VARCHAR).build();
    assertEquals(expected, result.schema());
    List<ColumnHandle> cols = parseFixture.tracker.internalSchema().columns();
    assertFalse(isImplicit(cols, 0));
    assertTrue(isImplicit(cols, 1));
    assertTrue(isImplicit(cols, 2));
    assertTrue(isImplicit(cols, 3));
    assertTrue(isImplicit(cols, 4));
    assertTrue(isImplicit(cols, 5));
}
Also used : ColumnHandle(org.apache.drill.exec.physical.impl.scan.v3.schema.MutableTupleSchema.ColumnHandle) Configuration(org.apache.hadoop.conf.Configuration) DrillFileSystem(org.apache.drill.exec.store.dfs.DrillFileSystem) 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) SubOperatorTest(org.apache.drill.test.SubOperatorTest) EvfTest(org.apache.drill.categories.EvfTest) Test(org.junit.Test)

Example 8 with ParseResult

use of org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ParseResult in project drill by apache.

the class TestImplicitColumnResolver method testProvidedImplicitCols.

@Test
public void testProvidedImplicitCols() {
    TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).add("myFqn", MinorType.VARCHAR).addNullable("myFilePath", MinorType.VARCHAR).add("myFileName", MinorType.VARCHAR).add("mySuffix", MinorType.VARCHAR).addNullable("myDir", MinorType.VARCHAR).build();
    SchemaUtils.markImplicit(providedSchema.metadata("myFqn"), ColumnMetadata.IMPLICIT_FQN);
    // Sic, to test case sensitivity
    SchemaUtils.markImplicit(providedSchema.metadata("myFilePath"), ColumnMetadata.IMPLICIT_FILEPATH.toUpperCase());
    SchemaUtils.markImplicit(providedSchema.metadata("myFileName"), ColumnMetadata.IMPLICIT_FILENAME);
    SchemaUtils.markImplicit(providedSchema.metadata("mySuffix"), ColumnMetadata.IMPLICIT_SUFFIX);
    SchemaUtils.markAsPartition(providedSchema.metadata("myDir"), 0);
    ParserFixture parseFixture = new ParserFixture(RowSetTestUtils.projectAll());
    parseFixture.tracker.applyProvidedSchema(providedSchema);
    parseFixture.options.maxPartitionDepth(1);
    ParseResult result = parseFixture.parseImplicit();
    assertEquals(5, result.columns().size());
    TupleMetadata expected = new SchemaBuilder().add("myFqn", MinorType.VARCHAR).addNullable("myFilePath", MinorType.VARCHAR).add("myFileName", MinorType.VARCHAR).add("mySuffix", MinorType.VARCHAR).addNullable("myDir", MinorType.VARCHAR).build();
    assertEquals(expected, result.schema());
    List<ColumnHandle> cols = parseFixture.tracker.internalSchema().columns();
    assertFalse(isImplicit(cols, 0));
    assertTrue(isImplicit(cols, 1));
    assertTrue(isImplicit(cols, 2));
    assertTrue(isImplicit(cols, 3));
    assertTrue(isImplicit(cols, 4));
    assertTrue(isImplicit(cols, 5));
}
Also used : ColumnHandle(org.apache.drill.exec.physical.impl.scan.v3.schema.MutableTupleSchema.ColumnHandle) 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) SubOperatorTest(org.apache.drill.test.SubOperatorTest) EvfTest(org.apache.drill.categories.EvfTest) Test(org.junit.Test)

Example 9 with ParseResult

use of org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ParseResult in project drill by apache.

the class TestImplicitColumnResolver method testImplicitOnlyWildcard.

@Test
public void testImplicitOnlyWildcard() {
    ParserFixture parseFixture = new ParserFixture(RowSetTestUtils.projectList(ScanTestUtils.FULLY_QUALIFIED_NAME_COL, SchemaPath.DYNAMIC_STAR, ScanTestUtils.FILE_NAME_COL));
    ParseResult result = parseFixture.parseImplicit();
    assertEquals(2, result.columns().size());
    assertTrue(parseFixture.tracker.isResolved());
    assertSame(ProjectionType.ALL, parseFixture.tracker.projectionType());
}
Also used : ParseResult(org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ParseResult) ProjectionParseResult(org.apache.drill.exec.physical.impl.scan.v3.schema.ScanProjectionParser.ProjectionParseResult) SubOperatorTest(org.apache.drill.test.SubOperatorTest) EvfTest(org.apache.drill.categories.EvfTest) Test(org.junit.Test)

Example 10 with ParseResult

use of org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ParseResult 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)17 ProjectionParseResult (org.apache.drill.exec.physical.impl.scan.v3.schema.ScanProjectionParser.ProjectionParseResult)17 Test (org.junit.Test)17 ParseResult (org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ParseResult)15 SubOperatorTest (org.apache.drill.test.SubOperatorTest)15 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)11 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)11 ColumnHandle (org.apache.drill.exec.physical.impl.scan.v3.schema.MutableTupleSchema.ColumnHandle)7 DynamicTupleFilter (org.apache.drill.exec.physical.impl.scan.v3.schema.DynamicSchemaFilter.DynamicTupleFilter)2 ProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter)2 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)2 BaseTest (org.apache.drill.test.BaseTest)2 ImplicitColumnOptions (org.apache.drill.exec.physical.impl.scan.v3.file.ImplicitColumnResolver.ImplicitColumnOptions)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 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)1 DrillFileSystem (org.apache.drill.exec.store.dfs.DrillFileSystem)1 Configuration (org.apache.hadoop.conf.Configuration)1