use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestSchemaSmoothing method doResolve.
private ResolvedRow doResolve(SchemaSmoother smoother, TupleMetadata schema) {
final NullColumnBuilder builder = new NullBuilderBuilder().build();
final ResolvedRow rootTuple = new ResolvedRow(builder);
smoother.resolve(schema, rootTuple);
return rootTuple;
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestSchemaSmoothing method testSamePartitionLength.
/**
* If using the legacy wildcard expansion, reuse schema if partition paths
* are the same length.
*/
@Test
public void testSamePartitionLength() {
// Set up the file metadata manager
Path filePathA = new Path("hdfs:///w/x/y/a.csv");
Path filePathB = new Path("hdfs:///w/x/y/b.csv");
ImplicitColumnManager metadataManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(Lists.newArrayList(filePathA, filePathB)));
// Set up the scan level projection
ScanLevelProjection scanProj = ScanLevelProjection.build(ScanTestUtils.projectAllWithAllImplicit(2), ScanTestUtils.parsers(metadataManager.projectionParser()));
// Define the schema smoother
SchemaSmoother smoother = new SchemaSmoother(scanProj, ScanTestUtils.resolvers(metadataManager));
TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
TupleMetadata expectedSchema = ScanTestUtils.expandImplicit(tableSchema, metadataManager, 2);
{
metadataManager.startFile(filePathA);
ResolvedRow rootTuple = doResolve(smoother, tableSchema);
assertTrue(ScanTestUtils.schema(rootTuple).isEquivalent(expectedSchema));
}
{
metadataManager.startFile(filePathB);
ResolvedRow rootTuple = doResolve(smoother, tableSchema);
assertEquals(1, smoother.schemaVersion());
assertTrue(ScanTestUtils.schema(rootTuple).isEquivalent(expectedSchema));
}
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestImplicitColumnProjection method testFileMetadata.
/**
* Test a query with explicit mention of file metadata columns.
*/
@Test
public void testFileMetadata() {
Path filePath = new Path("hdfs:///w/x/y/z.csv");
ImplicitColumnManager metadataManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
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), ScanTestUtils.parsers(metadataManager.projectionParser()));
assertEquals(5, scanProj.columns().size());
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());
// 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(5, columns.size());
assertEquals("/w/x/y/z.csv", ((MetadataColumn) columns.get(1)).value());
assertEquals("/w/x/y", ((MetadataColumn) columns.get(2)).value());
assertEquals("z.csv", ((MetadataColumn) columns.get(3)).value());
assertEquals("csv", ((MetadataColumn) columns.get(4)).value());
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestSchemaSmoothing method testDisjoint.
/**
* Case in which the table schema and prior are disjoint
* sets. Discard the prior schema.
*/
@Test
public void testDisjoint() {
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers());
final SchemaSmoother smoother = new SchemaSmoother(scanProj, ScanTestUtils.resolvers());
final TupleMetadata priorSchema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
final TupleMetadata tableSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).buildSchema();
{
doResolve(smoother, priorSchema);
}
{
final ResolvedRow rootTuple = doResolve(smoother, tableSchema);
assertEquals(2, smoother.schemaVersion());
assertTrue(ScanTestUtils.schema(rootTuple).isEquivalent(tableSchema));
}
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestSchemaSmoothing method testSameSchemas.
/**
* The prior and table schemas are identical. Preserve the prior
* schema (though, the output is no different than if we discarded
* the prior schema...)
*/
@Test
public void testSameSchemas() {
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers());
final SchemaSmoother smoother = new SchemaSmoother(scanProj, ScanTestUtils.resolvers());
final TupleMetadata priorSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
final TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
{
doResolve(smoother, priorSchema);
}
{
final ResolvedRow rootTuple = doResolve(smoother, tableSchema);
assertEquals(1, smoother.schemaVersion());
final TupleMetadata actualSchema = ScanTestUtils.schema(rootTuple);
assertTrue(actualSchema.isEquivalent(tableSchema));
assertTrue(actualSchema.isEquivalent(priorSchema));
}
}
Aggregations