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));
}
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));
}
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));
}
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());
}
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());
}
Aggregations