use of org.apache.drill.exec.record.metadata.SchemaBuilder 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.record.metadata.SchemaBuilder 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.record.metadata.SchemaBuilder 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();
}
use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.
the class TestResultSetLoaderEmptyProject method testDisjointSchema.
/**
* Verify that a disjoint schema (projection does not overlap with
* table schema) is treated the same as an empty projection.
*/
@Test
public void testDisjointSchema() {
List<SchemaPath> selection = Lists.newArrayList(SchemaPath.getSimplePath("a"), SchemaPath.getSimplePath("b"));
TupleMetadata schema = new SchemaBuilder().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);
assertTrue(rsLoader.isProjectionEmpty());
rsLoader.close();
}
use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.
the class TestResultSetLoaderEmptyProject method testNonEmptySchema.
/**
* Verify that skip rows works even if the the projection is non-empty.
*/
@Test
public void testNonEmptySchema() {
List<SchemaPath> selection = Lists.newArrayList(SchemaPath.getSimplePath("a"), SchemaPath.getSimplePath("b"));
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.INT).buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().projection(Projections.parse(selection)).readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
assertFalse(rsLoader.isProjectionEmpty());
// Skip 10 rows. Columns are of required types, so are filled
// with zeros.
rsLoader.startBatch();
int rowCount = 10;
rsLoader.skipRows(rowCount);
// Verify
RowSetBuilder builder = fixture.rowSetBuilder(schema);
for (int i = 0; i < rowCount; i++) {
builder.addRow(0, 0);
}
RowSetUtilities.verify(builder.build(), fixture.wrap(rsLoader.harvest()));
rsLoader.close();
}
Aggregations