use of org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn in project drill by apache.
the class ReaderSchemaOrchestrator method projectMetadata.
/**
* Sets {@code PROJECT_METADATA} implicit column value.
*
* @param projectMetadata whether {@code PROJECT_METADATA} should be replaced
* @return {@code true} if {@code PROJECT_METADATA} implicit column
* is present in scan projection and its value is updated
*/
private boolean projectMetadata(boolean projectMetadata) {
ImplicitInternalFileColumns original;
ImplicitInternalFileColumns newColumn;
if (projectMetadata) {
original = ImplicitInternalFileColumns.USE_METADATA;
newColumn = ImplicitInternalFileColumns.PROJECT_METADATA;
} else {
original = ImplicitInternalFileColumns.PROJECT_METADATA;
newColumn = ImplicitInternalFileColumns.USE_METADATA;
}
List<ColumnProjection> outputColumns = scanOrchestrator.scanProj.columns();
for (int i = 0; i < outputColumns.size(); i++) {
ColumnProjection outputColumn = outputColumns.get(i);
if (outputColumn instanceof FileMetadataColumn) {
FileMetadataColumn metadataColumn = (FileMetadataColumn) outputColumn;
if (metadataColumn.defn().defn == original) {
projectMetadata = scanOrchestrator.scanProj.requestedCols().stream().anyMatch(SchemaPath.getSimplePath(metadataColumn.name())::equals);
if (projectMetadata) {
outputColumns.set(i, new FileMetadataColumn(metadataColumn.name(), new FileMetadataColumnDefn(metadataColumn.defn().colName(), newColumn)));
}
return projectMetadata;
}
}
}
return false;
}
use of org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn in project drill by apache.
the class TestImplicitColumnProjection method testProjectList.
/**
* Test the file projection planner with metadata.
*/
@Test
public void testProjectList() {
Path filePath = new Path("hdfs:///w/x/y/z.csv");
ImplicitColumnManager metadataManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(ScanTestUtils.FILE_NAME_COL, "a", ScanTestUtils.partitionColName(0)), ScanTestUtils.parsers(metadataManager.projectionParser()));
assertEquals(3, scanProj.columns().size());
// Scan-level projection: defines the columns
{
assertTrue(scanProj.columns().get(0) instanceof FileMetadataColumn);
FileMetadataColumn col0 = (FileMetadataColumn) scanProj.columns().get(0);
assertTrue(col0 instanceof FileMetadataColumn);
assertEquals(ScanTestUtils.FILE_NAME_COL, col0.name());
assertEquals(MinorType.VARCHAR, col0.schema().getType().getMinorType());
assertEquals(DataMode.REQUIRED, col0.schema().getType().getMode());
ColumnProjection col1 = scanProj.columns().get(1);
assertTrue(col1 instanceof UnresolvedColumn);
assertEquals("a", col1.name());
assertTrue(scanProj.columns().get(2) instanceof PartitionColumn);
PartitionColumn col2 = (PartitionColumn) scanProj.columns().get(2);
assertTrue(col2 instanceof PartitionColumn);
assertEquals(ScanTestUtils.partitionColName(0), col2.name());
assertEquals(MinorType.VARCHAR, col2.schema().getType().getMinorType());
assertEquals(DataMode.OPTIONAL, col2.schema().getType().getMode());
}
// Schema-level projection, fills in values.
TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).buildSchema();
metadataManager.startFile(filePath);
NullColumnBuilder builder = new NullBuilderBuilder().build();
ResolvedRow rootTuple = new ResolvedRow(builder);
new ExplicitSchemaProjection(scanProj, tableSchema, rootTuple, ScanTestUtils.resolvers(metadataManager));
List<ResolvedColumn> columns = rootTuple.columns();
assertEquals(3, columns.size());
{
assertTrue(columns.get(0) instanceof FileMetadataColumn);
FileMetadataColumn col0 = (FileMetadataColumn) columns.get(0);
assertTrue(col0 instanceof FileMetadataColumn);
assertEquals(ScanTestUtils.FILE_NAME_COL, col0.name());
assertEquals("z.csv", col0.value());
assertEquals(MinorType.VARCHAR, col0.schema().getType().getMinorType());
assertEquals(DataMode.REQUIRED, col0.schema().getType().getMode());
ResolvedColumn col1 = columns.get(1);
assertEquals("a", col1.name());
assertTrue(columns.get(2) instanceof PartitionColumn);
PartitionColumn col2 = (PartitionColumn) columns.get(2);
assertTrue(col2 instanceof PartitionColumn);
assertEquals(ScanTestUtils.partitionColName(0), col2.name());
assertEquals("x", col2.value());
assertEquals(MinorType.VARCHAR, col2.schema().getType().getMinorType());
assertEquals(DataMode.OPTIONAL, col2.schema().getType().getMode());
}
// Verify that the file metadata columns were picked out
assertEquals(2, metadataManager.metadataColumns().size());
assertSame(columns.get(0), metadataManager.metadataColumns().get(0));
assertSame(columns.get(2), metadataManager.metadataColumns().get(1));
}
use of org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn in project drill by apache.
the class TestColumnsArrayParser method testMetadataColumnsWithColumnsArray.
/**
* The `columns` column is special: can't be used with other column names.
* Make sure that the rule <i>does not</i> apply to implicit columns.
*/
@Test
public void testMetadataColumnsWithColumnsArray() {
Path filePath = new Path("hdfs:///w/x/y/z.csv");
ImplicitColumnManager metadataManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(ScanTestUtils.FILE_NAME_COL, ColumnsScanFramework.COLUMNS_COL, ScanTestUtils.SUFFIX_COL), ScanTestUtils.parsers(new ColumnsArrayParser(true), metadataManager.projectionParser()));
assertFalse(scanProj.projectAll());
assertEquals(3, scanProj.columns().size());
assertEquals(ScanTestUtils.FILE_NAME_COL, scanProj.columns().get(0).name());
assertEquals(ColumnsScanFramework.COLUMNS_COL, scanProj.columns().get(1).name());
assertEquals(ScanTestUtils.SUFFIX_COL, scanProj.columns().get(2).name());
// Verify column type
assertTrue(scanProj.columns().get(0) instanceof FileMetadataColumn);
assertTrue(scanProj.columns().get(1) instanceof UnresolvedColumnsArrayColumn);
assertTrue(scanProj.columns().get(2) instanceof FileMetadataColumn);
}
use of org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn in project drill by apache.
the class TestImplicitColumnParser method testFileMetadataColumnSelection.
/**
* Test including file metadata (AKA "implicit columns") in the project
* list.
*/
@Test
public void testFileMetadataColumnSelection() {
Path filePath = new Path("hdfs:///w/x/y/z.csv");
ImplicitColumnManager implictColManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
// Simulate SELECT a, fqn, filEPath, filename, suffix ...
ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a", ScanTestUtils.FULLY_QUALIFIED_NAME_COL, // Sic, to test case sensitivity
"filEPath", ScanTestUtils.FILE_NAME_COL, ScanTestUtils.SUFFIX_COL), Lists.newArrayList(implictColManager.projectionParser()));
assertFalse(scanProj.projectAll());
assertEquals(5, scanProj.requestedCols().size());
assertEquals(5, scanProj.columns().size());
assertEquals("a", scanProj.columns().get(0).name());
assertEquals(ScanTestUtils.FULLY_QUALIFIED_NAME_COL, scanProj.columns().get(1).name());
assertEquals("filEPath", scanProj.columns().get(2).name());
assertEquals(ScanTestUtils.FILE_NAME_COL, scanProj.columns().get(3).name());
assertEquals(ScanTestUtils.SUFFIX_COL, scanProj.columns().get(4).name());
// Verify column type
assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumn);
assertTrue(scanProj.columns().get(1) instanceof FileMetadataColumn);
assertTrue(scanProj.columns().get(2) instanceof FileMetadataColumn);
assertTrue(scanProj.columns().get(3) instanceof FileMetadataColumn);
assertTrue(scanProj.columns().get(4) instanceof FileMetadataColumn);
assertTrue(implictColManager.hasImplicitCols());
}
use of org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn in project drill by apache.
the class TestImplicitColumnParser method testShadowed.
/**
* Verify that names that look like metadata columns, but appear
* to be maps or arrays, are not interpreted as metadata. That is,
* the projected table map or array "shadows" the metadata column.
*/
@Test
public void testShadowed() {
Path filePath = new Path("hdfs:///w/x/y/z.csv");
ImplicitColumnManager implictColManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(ScanTestUtils.FILE_NAME_COL + ".a", ScanTestUtils.FILE_PATH_COL + "[0]", ScanTestUtils.partitionColName(0) + ".b", ScanTestUtils.partitionColName(1) + "[0]", ScanTestUtils.SUFFIX_COL), Lists.newArrayList(implictColManager.projectionParser()));
List<ColumnProjection> cols = scanProj.columns();
assertEquals(5, cols.size());
for (int i = 0; i < 4; i++) {
assertTrue(scanProj.columns().get(i) instanceof UnresolvedColumn);
}
assertTrue(scanProj.columns().get(4) instanceof FileMetadataColumn);
}
Aggregations