use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestSchemaSmoothing method testReordering.
/**
* Preserve the prior schema if table is a subset. Map the table
* columns to the output using the prior schema ordering.
*/
@Test
public void testReordering() {
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers());
final SchemaSmoother smoother = new SchemaSmoother(scanProj, ScanTestUtils.resolvers());
final TupleMetadata priorSchema = new SchemaBuilder().addNullable("a", MinorType.INT).add("b", MinorType.VARCHAR).addArray("c", MinorType.BIGINT).buildSchema();
final TupleMetadata tableSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).addNullable("a", MinorType.INT).buildSchema();
{
doResolve(smoother, priorSchema);
}
{
final ResolvedRow rootTuple = doResolve(smoother, tableSchema);
assertEquals(1, smoother.schemaVersion());
assertTrue(ScanTestUtils.schema(rootTuple).isEquivalent(priorSchema));
}
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestSchemaSmoothing method testMissingNullableColumns.
/**
* Preserve the prior schema if table is a subset and missing columns
* are nullable or repeated.
*/
@Test
public void testMissingNullableColumns() {
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers());
final SchemaSmoother smoother = new SchemaSmoother(scanProj, ScanTestUtils.resolvers());
final TupleMetadata priorSchema = new SchemaBuilder().addNullable("a", MinorType.INT).add("b", MinorType.VARCHAR).addArray("c", MinorType.BIGINT).buildSchema();
final TupleMetadata tableSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).buildSchema();
{
doResolve(smoother, priorSchema);
}
{
final ResolvedRow rootTuple = doResolve(smoother, tableSchema);
assertEquals(1, smoother.schemaVersion());
assertTrue(ScanTestUtils.schema(rootTuple).isEquivalent(priorSchema));
}
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestSchemaSmoothing method testLongerPartitionLength.
/**
* If using the legacy wildcard expansion, we are able to use the same
* schema even if the new partition path is longer than the previous.
* Because all file names are provided up front.
*/
@Test
public void testLongerPartitionLength() {
// Set up the file metadata manager
Path filePathA = new Path("hdfs:///w/x/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 TestSchemaSmoothing method testSmaller.
/**
* Case in which the table schema is a superset of the prior
* schema. Discard prior schema. Turn off auto expansion of
* metadata for a simpler test.
*/
@Test
public void testSmaller() {
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("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
{
final NullColumnBuilder builder = new NullBuilderBuilder().build();
final ResolvedRow rootTuple = new ResolvedRow(builder);
smoother.resolve(priorSchema, rootTuple);
assertEquals(1, smoother.schemaVersion());
assertTrue(ScanTestUtils.schema(rootTuple).isEquivalent(priorSchema));
}
{
final NullColumnBuilder builder = new NullBuilderBuilder().build();
final ResolvedRow rootTuple = new ResolvedRow(builder);
smoother.resolve(tableSchema, rootTuple);
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 testShorterPartitionLength.
/**
* If using the legacy wildcard expansion, reuse schema if the new partition path
* is shorter than the previous. (Unneeded partitions will be set to null by the
* scan projector.)
*/
@Test
public void testShorterPartitionLength() {
// Set up the file metadata manager
Path filePathA = new Path("hdfs:///w/x/y/a.csv");
Path filePathB = new Path("hdfs:///w/x/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));
}
}
Aggregations