use of org.apache.drill.exec.physical.resultSet.ResultSetLoader in project drill by apache.
the class TestResultSetLoaderUnions method testListofListofScalar.
/**
* The semantics of the ListVector are such that it allows
* multi-dimensional lists. In this way, it is like a (slightly
* more normalized) version of the repeated list vector. This form
* allows arrays to be null.
* <p>
* This test verifies that the (non-repeated) list vector can
* be used to create multi-dimensional arrays in the result set
* loader layer. However, the rest of Drill does not support this
* functionality at present, so this test is more of a proof-of-
* concept than a necessity.
*/
@Test
public void testListofListofScalar() {
// JSON equivalent: {a: [[1, 2], [3, 4]]}
final ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator());
final RowSetLoader writer = rsLoader.writer();
// Can write a batch as if this was a repeated Varchar, except
// that any value can also be null.
rsLoader.startBatch();
writer.addColumn(MaterializedField.create("a", Types.optional(MinorType.LIST)));
final ArrayWriter outerArray = writer.array("a");
final VariantWriter outerVariant = outerArray.variant();
outerVariant.addMember(MinorType.LIST);
final ArrayWriter innerArray = outerVariant.array();
final VariantWriter innerVariant = innerArray.variant();
innerVariant.addMember(MinorType.INT);
writer.addSingleCol(listValue(listValue(1, 2), listValue(3, 4)));
final RowSet results = fixture.wrap(rsLoader.harvest());
// Verify metadata
final ListVector outer = (ListVector) results.container().getValueVector(0).getValueVector();
final MajorType outerType = outer.getField().getType();
assertEquals(1, outerType.getSubTypeCount());
assertEquals(MinorType.LIST, outerType.getSubType(0));
assertEquals(1, outer.getField().getChildren().size());
final ListVector inner = (ListVector) outer.getDataVector();
assertSame(inner.getField(), outer.getField().getChildren().iterator().next());
final MajorType innerType = inner.getField().getType();
assertEquals(1, innerType.getSubTypeCount());
assertEquals(MinorType.INT, innerType.getSubType(0));
assertEquals(1, inner.getField().getChildren().size());
final ValueVector data = inner.getDataVector();
assertSame(data.getField(), inner.getField().getChildren().iterator().next());
assertEquals(MinorType.INT, data.getField().getType().getMinorType());
assertEquals(DataMode.OPTIONAL, data.getField().getType().getMode());
assertTrue(data instanceof NullableIntVector);
// Note use of TupleMetadata: BatchSchema can't hold the
// structure of a list.
final TupleMetadata expectedSchema = new SchemaBuilder().addList("a").addList().addType(MinorType.INT).resumeUnion().resumeSchema().buildSchema();
final RowSet expected = new RowSetBuilder(fixture.allocator(), expectedSchema).addSingleCol(listValue(listValue(1, 2), listValue(3, 4))).build();
RowSetUtilities.verify(expected, results);
}
use of org.apache.drill.exec.physical.resultSet.ResultSetLoader in project drill by apache.
the class TestResultSetLoaderUnions method testUnionBasics.
@Test
public void testUnionBasics() {
final TupleMetadata schema = new SchemaBuilder().add("id", MinorType.INT).addUnion("u").addType(MinorType.VARCHAR).addMap().addNullable("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).resumeUnion().resumeSchema().buildSchema();
final ResultSetLoaderImpl.ResultSetOptions options = new ResultSetOptionBuilder().readerSchema(schema).build();
final ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
final RowSetLoader writer = rsLoader.writer();
// Sanity check of writer structure
final ObjectWriter wo = writer.column(1);
assertEquals(ObjectType.VARIANT, wo.type());
final VariantWriter vw = wo.variant();
assertTrue(vw.hasType(MinorType.VARCHAR));
assertNotNull(vw.memberWriter(MinorType.VARCHAR));
assertTrue(vw.hasType(MinorType.MAP));
assertNotNull(vw.memberWriter(MinorType.MAP));
// Write values
rsLoader.startBatch();
writer.addRow(1, "first").addRow(2, mapValue(20, "fred")).addRow(3, null).addRow(4, mapValue(40, null)).addRow(5, "last");
// Verify the values.
// (Relies on the row set level union tests having passed.)
final SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(1, "first").addRow(2, mapValue(20, "fred")).addRow(3, null).addRow(4, mapValue(40, null)).addRow(5, "last").build();
RowSetUtilities.verify(expected, fixture.wrap(rsLoader.harvest()));
}
use of org.apache.drill.exec.physical.resultSet.ResultSetLoader in project drill by apache.
the class TestResultSetLoaderDictArray method testDictValue.
@Test
public void testDictValue() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addDictArray("d", MinorType.VARCHAR).dictValue().key(MinorType.VARCHAR).value(MinorType.VARCHAR).resumeDict().resumeSchema().buildSchema();
ResultSetLoaderImpl.ResultSetOptions options = new ResultSetOptionBuilder().readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Write a couple of rows
rsLoader.startBatch();
rootWriter.addRow(10, objArray(map("a", map("a", "a1", "b", "a2", "c", "a3"), "b", map("d", "a4"), "c", map()), map("b", map("b", "a2")))).addRow(20, objArray()).addRow(30, objArray(map("a", map("a", "b1", "b", "b1")), map("b", map("e", "b2"), "a", map("h", "b1", "g", "b3"), "c", map("a", "b4")), map("b", map("a", "b3", "c", "c3"), "a", map())));
// Verify the batch
RowSet actual = fixture.wrap(rsLoader.harvest());
SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray(map("a", map("a", "a1", "b", "a2", "c", "a3"), "b", map("d", "a4"), "c", map()), map("b", map("b", "a2")))).addRow(20, objArray()).addRow(30, objArray(map("a", map("a", "b1", "b", "b1")), map("b", map("e", "b2"), "a", map("h", "b1", "g", "b3"), "c", map("a", "b4")), map("b", map("a", "b3", "c", "c3"), "a", map()))).build();
RowSetUtilities.verify(expected, actual);
rsLoader.close();
}
use of org.apache.drill.exec.physical.resultSet.ResultSetLoader in project drill by apache.
the class TestResultSetLoaderEmptyProject method testDisjointMapProjection.
/**
* Test disjoint projection, but with maps. Project top-level columns
* a, b, when those columns actually appear in a map which is not
* projected.
*/
@Test
public void testDisjointMapProjection() {
List<SchemaPath> selection = Lists.newArrayList(SchemaPath.getSimplePath("a"), SchemaPath.getSimplePath("b"));
TupleMetadata schema = new SchemaBuilder().addMap("map").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);
assertTrue(rsLoader.isProjectionEmpty());
rsLoader.close();
}
use of org.apache.drill.exec.physical.resultSet.ResultSetLoader in project drill by apache.
the class TestResultSetLoaderEmptyProject method testEmptyMapProjection.
@Test
public void testEmptyMapProjection() {
List<SchemaPath> selection = Lists.newArrayList();
TupleMetadata schema = new SchemaBuilder().addMap("map").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);
assertTrue(rsLoader.isProjectionEmpty());
// Sanity test to verify row skipping with maps
int rowCount = 5000;
rsLoader.startBatch();
int skipped = rsLoader.skipRows(rowCount);
assertEquals(skipped, rowCount);
VectorContainer output = rsLoader.harvest();
assertEquals(rowCount, output.getRecordCount());
assertEquals(0, output.getNumberOfColumns());
output.zeroVectors();
rsLoader.close();
}
Aggregations