use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestSchemaSmoothing method testSmoothingProjection.
/**
* Low-level test of the smoothing projection, including the exceptions
* it throws when things are not going its way.
*/
@Test
public void testSmoothingProjection() {
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers());
// Table 1: (a: nullable bigint, b)
final TupleMetadata schema1 = new SchemaBuilder().addNullable("a", MinorType.BIGINT).addNullable("b", MinorType.VARCHAR).add("c", MinorType.FLOAT8).buildSchema();
ResolvedRow priorSchema;
{
final NullColumnBuilder builder = new NullBuilderBuilder().build();
final ResolvedRow rootTuple = new ResolvedRow(builder);
new WildcardProjection(scanProj, schema1, rootTuple, ScanTestUtils.resolvers());
priorSchema = rootTuple;
}
// Table 2: (a: nullable bigint, c), column omitted, original schema preserved
final TupleMetadata schema2 = new SchemaBuilder().addNullable("a", MinorType.BIGINT).add("c", MinorType.FLOAT8).buildSchema();
try {
final NullColumnBuilder builder = new NullBuilderBuilder().build();
final ResolvedRow rootTuple = new ResolvedRow(builder);
new SmoothingProjection(scanProj, schema2, priorSchema, rootTuple, ScanTestUtils.resolvers());
assertTrue(schema1.isEquivalent(ScanTestUtils.schema(rootTuple)));
priorSchema = rootTuple;
} catch (final IncompatibleSchemaException e) {
fail();
}
// Table 3: (a, c, d), column added, must replan schema
final TupleMetadata schema3 = new SchemaBuilder().addNullable("a", MinorType.BIGINT).addNullable("b", MinorType.VARCHAR).add("c", MinorType.FLOAT8).add("d", MinorType.INT).buildSchema();
try {
final NullColumnBuilder builder = new NullBuilderBuilder().build();
final ResolvedRow rootTuple = new ResolvedRow(builder);
new SmoothingProjection(scanProj, schema3, priorSchema, rootTuple, ScanTestUtils.resolvers());
fail();
} catch (final IncompatibleSchemaException e) {
// Expected
}
// Table 4: (a: double), change type must replan schema
final TupleMetadata schema4 = new SchemaBuilder().addNullable("a", MinorType.FLOAT8).addNullable("b", MinorType.VARCHAR).add("c", MinorType.FLOAT8).buildSchema();
try {
final NullColumnBuilder builder = new NullBuilderBuilder().build();
final ResolvedRow rootTuple = new ResolvedRow(builder);
new SmoothingProjection(scanProj, schema4, priorSchema, rootTuple, ScanTestUtils.resolvers());
fail();
} catch (final IncompatibleSchemaException e) {
// Expected
}
// Table 5: Drop a non-nullable column, must replan
final TupleMetadata schema6 = new SchemaBuilder().addNullable("a", MinorType.BIGINT).addNullable("b", MinorType.VARCHAR).buildSchema();
try {
final NullColumnBuilder builder = new NullBuilderBuilder().build();
final ResolvedRow rootTuple = new ResolvedRow(builder);
new SmoothingProjection(scanProj, schema6, priorSchema, rootTuple, ScanTestUtils.resolvers());
fail();
} catch (final IncompatibleSchemaException e) {
// Expected
}
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestReaderLevelProjection method testOmittedMapMembers.
/**
* Test of a map with missing columns.
* table of (a{b, c}), project a.c, a.d, a.e.f
*/
@Test
public void testOmittedMapMembers() {
// Simulate SELECT a.c, a.d, a.e.f ...
final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("x", "a.c", "a.d", "a.e.f", "y"), ScanTestUtils.parsers());
assertEquals(3, scanProj.columns().size());
// Simulate a data source, with early schema, of (x, y, a{b, c})
final TupleMetadata tableSchema = new SchemaBuilder().add("x", MinorType.VARCHAR).add("y", MinorType.INT).addMap("a").add("b", MinorType.BIGINT).add("c", MinorType.FLOAT8).resumeSchema().buildSchema();
final NullColumnBuilder builder = new NullBuilderBuilder().build();
final ResolvedRow rootTuple = new ResolvedRow(builder);
new ExplicitSchemaProjection(scanProj, tableSchema, rootTuple, ScanTestUtils.resolvers());
final List<ResolvedColumn> columns = rootTuple.columns();
assertEquals(3, columns.size());
// Should have resolved a.b to a map column,
// a.d to a missing nested map, and a.e.f to a missing
// nested map member
// X is projected
final ResolvedColumn xCol = columns.get(0);
assertEquals("x", xCol.name());
assertTrue(xCol instanceof ResolvedTableColumn);
assertSame(rootTuple, xCol.source());
assertEquals(0, xCol.sourceIndex());
// Y is projected
final ResolvedColumn yCol = columns.get(2);
assertEquals("y", yCol.name());
assertTrue(yCol instanceof ResolvedTableColumn);
assertSame(rootTuple, yCol.source());
assertEquals(1, yCol.sourceIndex());
// A is projected
final ResolvedColumn aCol = columns.get(1);
assertEquals("a", aCol.name());
assertTrue(aCol instanceof ResolvedMapColumn);
final ResolvedMapColumn aMap = (ResolvedMapColumn) aCol;
final ResolvedTuple aMembers = aMap.members();
assertFalse(aMembers.isSimpleProjection());
assertNotNull(aMembers);
assertEquals(3, aMembers.columns().size());
// a.c is projected
final ResolvedColumn acCol = aMembers.columns().get(0);
assertEquals("c", acCol.name());
assertTrue(acCol instanceof ResolvedTableColumn);
assertEquals(1, acCol.sourceIndex());
// a.d is not in the table, is null
final ResolvedColumn adCol = aMembers.columns().get(1);
assertEquals("d", adCol.name());
assertTrue(adCol instanceof ResolvedNullColumn);
// a.e is not in the table, is implicitly a map
final ResolvedColumn aeCol = aMembers.columns().get(2);
assertEquals("e", aeCol.name());
assertTrue(aeCol instanceof ResolvedMapColumn);
final ResolvedMapColumn aeMap = (ResolvedMapColumn) aeCol;
final ResolvedTuple aeMembers = aeMap.members();
assertFalse(aeMembers.isSimpleProjection());
assertNotNull(aeMembers);
assertEquals(1, aeMembers.columns().size());
// a.d.f is a null column
final ResolvedColumn aefCol = aeMembers.columns().get(0);
assertEquals("f", aefCol.name());
assertTrue(aefCol instanceof ResolvedNullColumn);
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestRowBatchMerger method testMapArrayRevision.
/**
* Test that the merger mechanism can rewrite a map array to include
* projected null columns.
*/
@Test
public void testMapArrayRevision() {
// Create the first batch
TupleMetadata inputSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).addMapArray("a").add("c", MinorType.INT).resumeSchema().buildSchema();
RowSetSource input = new RowSetSource(fixture.rowSetBuilder(inputSchema).addRow("barney", mapArray(singleMap(10), singleMap(11), singleMap(12))).addRow("wilma", mapArray(singleMap(20), singleMap(21))).build());
// Create mappings
NullColumnBuilder builder = new NullBuilderBuilder().build();
ResolvedRow resolvedTuple = new ResolvedRow(builder);
resolvedTuple.add(new TestProjection(resolvedTuple, 0));
ResolvedMapColumn mapCol = new ResolvedMapColumn(resolvedTuple, inputSchema.column(1), 1);
resolvedTuple.add(mapCol);
ResolvedTuple map = mapCol.members();
map.add(new TestProjection(map, 0));
map.add(map.nullBuilder().add("null1"));
// Build the null values
ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
resolvedTuple.buildNulls(cache);
// LoadNulls
resolvedTuple.loadNulls(input.rowSet().rowCount());
// Do the merge
VectorContainer output = new VectorContainer(fixture.allocator());
resolvedTuple.project(input.rowSet().container(), output);
output.setRecordCount(input.rowSet().rowCount());
RowSet result = fixture.wrap(output);
// Verify
TupleMetadata expectedSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).addMapArray("a").add("c", MinorType.INT).addNullable("null1", MinorType.INT).resumeSchema().buildSchema();
RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow("barney", mapArray(mapValue(10, null), mapValue(11, null), mapValue(12, null))).addRow("wilma", mapArray(mapValue(20, null), mapValue(21, null))).build();
new RowSetComparison(expected).verifyAndClearAll(result);
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestRowBatchMerger method testSimpleFlat.
@Test
public void testSimpleFlat() {
// Create the first batch
RowSetSource first = makeFirst();
// Create the second batch
RowSetSource second = makeSecond();
ResolvedRow resolvedTuple = new ResolvedRow(null);
resolvedTuple.add(new TestProjection(first, 1));
resolvedTuple.add(new TestProjection(second, 0));
resolvedTuple.add(new TestProjection(second, 1));
resolvedTuple.add(new TestProjection(first, 0));
// Do the merge
VectorContainer output = new VectorContainer(fixture.allocator());
resolvedTuple.project(null, output);
output.setRecordCount(first.rowSet().rowCount());
RowSet result = fixture.wrap(output);
// Verify
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.INT).add("c", MinorType.VARCHAR).add("d", MinorType.VARCHAR).buildSchema();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, 1, "foo.csv", "barney").addRow(20, 2, "foo.csv", "wilma").build();
new RowSetComparison(expected).verifyAndClearAll(result);
}
use of org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow in project drill by apache.
the class TestRowBatchMerger method testMapRevision.
/**
* Test that the merger mechanism can rewrite a map to include
* projected null columns.
*/
@Test
public void testMapRevision() {
// Create the first batch
TupleMetadata inputSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).addMap("a").add("c", MinorType.INT).resumeSchema().buildSchema();
RowSetSource input = new RowSetSource(fixture.rowSetBuilder(inputSchema).addRow("barney", singleMap(10)).addRow("wilma", singleMap(20)).build());
// Create mappings
NullColumnBuilder builder = new NullBuilderBuilder().build();
ResolvedRow resolvedTuple = new ResolvedRow(builder);
resolvedTuple.add(new TestProjection(resolvedTuple, 0));
ResolvedMapColumn mapCol = new ResolvedMapColumn(resolvedTuple, inputSchema.column(1), 1);
resolvedTuple.add(mapCol);
ResolvedTuple map = mapCol.members();
map.add(new TestProjection(map, 0));
map.add(map.nullBuilder().add("null1"));
// Build the null values
ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
resolvedTuple.buildNulls(cache);
// LoadNulls
resolvedTuple.loadNulls(input.rowSet().rowCount());
// Do the merge
VectorContainer output = new VectorContainer(fixture.allocator());
resolvedTuple.project(input.rowSet().container(), output);
output.setRecordCount(input.rowSet().rowCount());
RowSet result = fixture.wrap(output);
// Verify
TupleMetadata expectedSchema = new SchemaBuilder().add("b", MinorType.VARCHAR).addMap("a").add("c", MinorType.INT).addNullable("null1", MinorType.INT).resumeSchema().buildSchema();
RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow("barney", mapValue(10, null)).addRow("wilma", mapValue(20, null)).build();
new RowSetComparison(expected).verifyAndClearAll(result);
}
Aggregations