use of org.apache.drill.exec.physical.rowSet.RowSetLoader in project drill by axbaretto.
the class TestResultSetLoaderLimits method testRowLimit.
/**
* Verify that the writer stops when reaching the row limit.
* In this case there is no look-ahead row.
*/
@Test
public void testRowLimit() {
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator());
assertEquals(ResultSetLoaderImpl.DEFAULT_ROW_COUNT, rsLoader.targetRowCount());
RowSetLoader rootWriter = rsLoader.writer();
rootWriter.addColumn(SchemaBuilder.columnSchema("s", MinorType.VARCHAR, DataMode.REQUIRED));
byte[] value = new byte[200];
Arrays.fill(value, (byte) 'X');
int count = 0;
rsLoader.startBatch();
while (!rootWriter.isFull()) {
rootWriter.start();
rootWriter.scalar(0).setBytes(value, value.length);
rootWriter.save();
count++;
}
assertEquals(ResultSetLoaderImpl.DEFAULT_ROW_COUNT, count);
assertEquals(count, rootWriter.rowCount());
rsLoader.harvest().clear();
// Do it again, a different way.
count = 0;
rsLoader.startBatch();
assertEquals(0, rootWriter.rowCount());
while (rootWriter.start()) {
rootWriter.scalar(0).setBytes(value, value.length);
rootWriter.save();
count++;
}
assertEquals(ResultSetLoaderImpl.DEFAULT_ROW_COUNT, count);
assertEquals(count, rootWriter.rowCount());
rsLoader.harvest().clear();
rsLoader.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSetLoader in project drill by axbaretto.
the class TestResultSetLoaderLimits method testDynamicLimit.
/**
* Test that the row limit can change between batches.
*/
@Test
public void testDynamicLimit() {
// Start with a small limit.
ResultSetOptions options = new OptionBuilder().setRowCountLimit(TEST_ROW_LIMIT).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
assertEquals(TEST_ROW_LIMIT, rsLoader.targetRowCount());
RowSetLoader rootWriter = rsLoader.writer();
rootWriter.addColumn(SchemaBuilder.columnSchema("s", MinorType.VARCHAR, DataMode.REQUIRED));
rsLoader.startBatch();
int count = fillToLimit(rootWriter);
assertEquals(TEST_ROW_LIMIT, count);
assertEquals(count, rootWriter.rowCount());
rsLoader.harvest().clear();
// Reset the batch size larger and fill a second batch
int newLimit = 8000;
rsLoader.setTargetRowCount(newLimit);
rsLoader.startBatch();
count = fillToLimit(rootWriter);
assertEquals(newLimit, count);
assertEquals(count, rootWriter.rowCount());
rsLoader.harvest().clear();
// Put the limit back to a lower number.
newLimit = 1000;
rsLoader.setTargetRowCount(newLimit);
rsLoader.startBatch();
count = fillToLimit(rootWriter);
assertEquals(newLimit, count);
assertEquals(count, rootWriter.rowCount());
rsLoader.harvest().clear();
rsLoader.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSetLoader in project drill by axbaretto.
the class TestResultSetLoaderMapArray method testBasics.
@Test
public void testBasics() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).add("d", MinorType.VARCHAR).resumeSchema().buildSchema();
ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Verify structure and schema
TupleMetadata actualSchema = rootWriter.schema();
assertEquals(2, actualSchema.size());
assertTrue(actualSchema.metadata(1).isArray());
assertTrue(actualSchema.metadata(1).isMap());
assertEquals(2, actualSchema.metadata("m").mapSchema().size());
assertEquals(2, actualSchema.column("m").getChildren().size());
// Write a couple of rows with arrays.
rsLoader.startBatch();
rootWriter.addRow(10, objArray(objArray(110, "d1.1"), objArray(120, "d2.2"))).addRow(20, objArray()).addRow(30, objArray(objArray(310, "d3.1"), objArray(320, "d3.2"), objArray(330, "d3.3")));
// Verify the first batch
RowSet actual = fixture.wrap(rsLoader.harvest());
SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray(objArray(110, "d1.1"), objArray(120, "d2.2"))).addRow(20, objArray()).addRow(30, objArray(objArray(310, "d3.1"), objArray(320, "d3.2"), objArray(330, "d3.3"))).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
// In the second, create a row, then add a map member.
// Should be back-filled to empty for the first row.
rsLoader.startBatch();
rootWriter.addRow(40, objArray(objArray(410, "d4.1"), objArray(420, "d4.2")));
TupleWriter mapWriter = rootWriter.array("m").tuple();
mapWriter.addColumn(SchemaBuilder.columnSchema("e", MinorType.VARCHAR, DataMode.OPTIONAL));
rootWriter.addRow(50, objArray(objArray(510, "d5.1", "e5.1"), objArray(520, "d5.2", null))).addRow(60, objArray(objArray(610, "d6.1", "e6.1"), objArray(620, "d6.2", null), objArray(630, "d6.3", "e6.3")));
// Verify the second batch
actual = fixture.wrap(rsLoader.harvest());
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).add("d", MinorType.VARCHAR).addNullable("e", MinorType.VARCHAR).resumeSchema().buildSchema();
expected = fixture.rowSetBuilder(expectedSchema).addRow(40, objArray(objArray(410, "d4.1", null), objArray(420, "d4.2", null))).addRow(50, objArray(objArray(510, "d5.1", "e5.1"), objArray(520, "d5.2", null))).addRow(60, objArray(objArray(610, "d6.1", "e6.1"), objArray(620, "d6.2", null), objArray(630, "d6.3", "e6.3"))).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
rsLoader.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSetLoader in project drill by axbaretto.
the class TestResultSetLoaderMapArray method testNestedArray.
@Test
public void testNestedArray() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).addArray("d", MinorType.VARCHAR).resumeSchema().buildSchema();
ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Write a couple of rows with arrays within arrays.
// (And, of course, the Varchar is actually an array of
// bytes, so that's three array levels.)
rsLoader.startBatch();
rootWriter.addRow(10, objArray(objArray(110, strArray("d1.1.1", "d1.1.2")), objArray(120, strArray("d1.2.1", "d1.2.2")))).addRow(20, objArray()).addRow(30, objArray(objArray(310, strArray("d3.1.1", "d3.2.2")), objArray(320, strArray()), objArray(330, strArray("d3.3.1", "d1.2.2"))));
// Verify the batch
RowSet actual = fixture.wrap(rsLoader.harvest());
SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray(objArray(110, strArray("d1.1.1", "d1.1.2")), objArray(120, strArray("d1.2.1", "d1.2.2")))).addRow(20, objArray()).addRow(30, objArray(objArray(310, strArray("d3.1.1", "d3.2.2")), objArray(320, strArray()), objArray(330, strArray("d3.3.1", "d1.2.2")))).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
rsLoader.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSetLoader in project drill by axbaretto.
the class TestResultSetLoaderMapArray method testOverwriteRow.
/**
* Version of the {#link TestResultSetLoaderProtocol#testOverwriteRow()} test
* that uses nested columns inside an array of maps. Here we must call
* <tt>start()</tt> to reset the array back to the initial start position after
* each "discard."
*/
@Test
public void testOverwriteRow() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("b", MinorType.INT).add("c", MinorType.VARCHAR).resumeSchema().buildSchema();
ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).setRowCountLimit(ValueVector.MAX_ROW_COUNT).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Can't use the shortcut to populate rows when doing overwrites.
ScalarWriter aWriter = rootWriter.scalar("a");
ArrayWriter maWriter = rootWriter.array("m");
TupleWriter mWriter = maWriter.tuple();
ScalarWriter bWriter = mWriter.scalar("b");
ScalarWriter cWriter = mWriter.scalar("c");
// Write 100,000 rows, overwriting 99% of them. This will cause vector
// overflow and data corruption if overwrite does not work; but will happily
// produce the correct result if everything works as it should.
byte[] value = new byte[512];
Arrays.fill(value, (byte) 'X');
int count = 0;
rsLoader.startBatch();
while (count < 10_000) {
rootWriter.start();
count++;
aWriter.setInt(count);
for (int i = 0; i < 10; i++) {
bWriter.setInt(count * 10 + i);
cWriter.setBytes(value, value.length);
maWriter.save();
}
if (count % 100 == 0) {
rootWriter.save();
}
}
// Verify using a reader.
RowSet result = fixture.wrap(rsLoader.harvest());
assertEquals(count / 100, result.rowCount());
RowSetReader reader = result.reader();
ArrayReader maReader = reader.array("m");
TupleReader mReader = maReader.tuple();
int rowId = 1;
while (reader.next()) {
assertEquals(rowId * 100, reader.scalar("a").getInt());
assertEquals(10, maReader.size());
for (int i = 0; i < 10; i++) {
maReader.setPosn(i);
assertEquals(rowId * 1000 + i, mReader.scalar("b").getInt());
assertTrue(Arrays.equals(value, mReader.scalar("c").getBytes()));
}
rowId++;
}
result.clear();
rsLoader.close();
}
Aggregations