use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderProjection method testMapArrayProjection.
/**
* Test a map array. Use the convenience methods to set values.
* Only the projected array members should appear in the harvested
* results.
*/
@Test
public void testMapArrayProjection() {
List<SchemaPath> selection = RowSetTestUtils.projectList("m1", "m2.d");
TupleMetadata schema = new SchemaBuilder().addMapArray("m1").add("a", MinorType.INT).add("b", MinorType.INT).resumeSchema().addMapArray("m2").add("c", MinorType.INT).add("d", MinorType.INT).resumeSchema().addMapArray("m3").add("e", MinorType.INT).add("f", MinorType.INT).resumeSchema().buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().projection(Projections.parse(selection)).readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Write a couple of rows.
rsLoader.startBatch();
rootWriter.addRow(objArray(objArray(10, 20), objArray(11, 21)), objArray(objArray(30, 40), objArray(31, 42)), objArray(objArray(50, 60), objArray(51, 62)));
rootWriter.addRow(objArray(objArray(110, 120), objArray(111, 121)), objArray(objArray(130, 140), objArray(131, 142)), objArray(objArray(150, 160), objArray(151, 162)));
// Verify. Only the projected columns appear in the result set.
TupleMetadata expectedSchema = new SchemaBuilder().addMapArray("m1").add("a", MinorType.INT).add("b", MinorType.INT).resumeSchema().addMapArray("m2").add("d", MinorType.INT).resumeSchema().buildSchema();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(objArray(objArray(10, 20), objArray(11, 21)), objArray(objArray(40), objArray(42))).addRow(objArray(objArray(110, 120), objArray(111, 121)), objArray(objArray(140), objArray(142))).build();
RowSetUtilities.verify(expected, fixture.wrap(rsLoader.harvest()));
rsLoader.close();
}
use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderProjection method testProjectionStatic.
/**
* Test imposing a selection mask between the client and the underlying
* vector container.
*/
@Test
public void testProjectionStatic() {
List<SchemaPath> selection = RowSetTestUtils.projectList("c", "b", "e");
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.INT).add("c", MinorType.INT).add("d", MinorType.INT).buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().projection(Projections.parse(selection)).readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
doProjectionTest(rsLoader);
}
use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderProjection method testMapProjectionMemberAndMap.
@Test
public void testMapProjectionMemberAndMap() {
// SELECT m1, m1.b
// This really means project all of m1; m1.b is along for the ride.
List<SchemaPath> selection = RowSetTestUtils.projectList("m1", "m1.b");
// Define an "early" reader schema consistent with the projection.
TupleMetadata schema = new SchemaBuilder().addMap("m1").add("a", MinorType.INT).add("b", MinorType.INT).resumeSchema().buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().projection(Projections.parse(selection)).readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Verify the projected columns
TupleMetadata actualSchema = rootWriter.tupleSchema();
ColumnMetadata m1Md = actualSchema.metadata("m1");
TupleWriter m1Writer = rootWriter.tuple("m1");
assertTrue(m1Md.isMap());
assertTrue(m1Writer.isProjected());
assertEquals(2, m1Md.tupleSchema().size());
assertTrue(m1Writer.column("a").isProjected());
assertTrue(m1Writer.column("b").isProjected());
// Write a couple of rows.
rsLoader.startBatch();
rootWriter.start();
rootWriter.addSingleCol(mapValue(1, 2)).addSingleCol(mapValue(11, 12));
// Verify. The whole map appears in the result set because the
// project list included the whole map as well as a map member.
SingleRowSet expected = fixture.rowSetBuilder(schema).addSingleCol(mapValue(1, 2)).addSingleCol(mapValue(11, 12)).build();
RowSetUtilities.verify(expected, fixture.wrap(rsLoader.harvest()));
rsLoader.close();
}
use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderProjection method testDictStringKeyAccess.
@Test
public void testDictStringKeyAccess() {
// the same as col['a'], but number is expected in brackets ([])
List<SchemaPath> selection = RowSetTestUtils.projectList("col.a");
TupleMetadata schema = new SchemaBuilder().addDict("col", MinorType.VARCHAR).value(MinorType.INT).resumeSchema().buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().projection(Projections.parse(selection)).readerSchema(schema).build();
// no validation error
new ResultSetLoaderImpl(fixture.allocator(), options);
}
use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderProjection method testArrayMapArrayConflict.
@Test
public void testArrayMapArrayConflict() {
List<SchemaPath> selection = RowSetTestUtils.projectList("col[0].child");
TupleMetadata schema = new SchemaBuilder().addArray("col", MinorType.VARCHAR).buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().projection(Projections.parse(selection)).readerSchema(schema).build();
try {
new ResultSetLoaderImpl(fixture.allocator(), options);
fail();
} catch (UserException e) {
assertTrue(e.getErrorType() == ErrorType.VALIDATION);
}
}
Aggregations