use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderOverflow method testOversizeArray.
/**
* Case where a single array fills up the vector to the maximum size
* limit. Overflow won't work here; the attempt will fail with a user
* exception.
*/
@Test
public void testOversizeArray() {
TupleMetadata schema = new SchemaBuilder().addArray("s", MinorType.VARCHAR).buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().rowCountLimit(ValueVector.MAX_ROW_COUNT).readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Create a single array as the column value in the first row. When
// this overflows, an exception is thrown since overflow is not possible.
rsLoader.startBatch();
byte[] value = new byte[473];
Arrays.fill(value, (byte) 'X');
rootWriter.start();
ScalarWriter array = rootWriter.array(0).scalar();
try {
for (int i = 0; i < ValueVector.MAX_ROW_COUNT; i++) {
array.setBytes(value, value.length);
}
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains("column value is larger than the maximum"));
}
rsLoader.close();
}
use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderOverflow method testBatchSizeLimit.
/**
* Test that the writer detects a vector overflow. The offending column
* value should be moved to the next batch.
*/
@Test
public void testBatchSizeLimit() {
TupleMetadata schema = new SchemaBuilder().add("s", MinorType.VARCHAR).buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().rowCountLimit(ValueVector.MAX_ROW_COUNT).readerSchema(schema).batchSizeLimit(// Data
8 * 1024 * 1024 + // Offsets, doubled because of +1
2 * ValueVector.MAX_ROW_COUNT * 4).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
rsLoader.startBatch();
byte[] value = new byte[512];
Arrays.fill(value, (byte) 'X');
// Our row count should include the overflow row
int expectedCount = 8 * 1024 * 1024 / value.length;
// First batch, with overflow
{
int count = 0;
while (!rootWriter.isFull()) {
rootWriter.start();
rootWriter.scalar(0).setBytes(value, value.length);
rootWriter.save();
count++;
}
assertEquals(expectedCount + 1, count);
// Loader's row count should include only "visible" rows
assertEquals(expectedCount, rootWriter.rowCount());
// Total count should include invisible and look-ahead rows.
assertEquals(expectedCount + 1, rsLoader.totalRowCount());
// Result should exclude the overflow row
VectorContainer container = rsLoader.harvest();
BatchValidator.validate(container);
RowSet result = fixture.wrap(container);
assertEquals(expectedCount, result.rowCount());
result.clear();
}
// Next batch should start with the overflow row
{
rsLoader.startBatch();
assertEquals(1, rootWriter.rowCount());
assertEquals(expectedCount + 1, rsLoader.totalRowCount());
VectorContainer container = rsLoader.harvest();
BatchValidator.validate(container);
RowSet result = fixture.wrap(container);
assertEquals(1, result.rowCount());
result.clear();
}
rsLoader.close();
}
use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderOverflow method testVectorSizeLimit.
/**
* Test that the writer detects a vector overflow. The offending column
* value should be moved to the next batch.
*/
@Test
public void testVectorSizeLimit() {
TupleMetadata schema = new SchemaBuilder().add("s", MinorType.VARCHAR).buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().rowCountLimit(ValueVector.MAX_ROW_COUNT).readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
rsLoader.startBatch();
byte[] value = new byte[512];
Arrays.fill(value, (byte) 'X');
// Number of rows should be driven by vector size.
// Our row count should include the overflow row
int expectedCount = ValueVector.MAX_BUFFER_SIZE / value.length;
{
int count = 0;
while (!rootWriter.isFull()) {
rootWriter.start();
rootWriter.scalar(0).setBytes(value, value.length);
rootWriter.save();
count++;
}
assertEquals(expectedCount + 1, count);
// Loader's row count should include only "visible" rows
assertEquals(expectedCount, rootWriter.rowCount());
// Total count should include invisible and look-ahead rows.
assertEquals(expectedCount + 1, rsLoader.totalRowCount());
// Result should exclude the overflow row
VectorContainer container = rsLoader.harvest();
BatchValidator.validate(container);
RowSet result = fixture.wrap(container);
assertEquals(expectedCount, result.rowCount());
result.clear();
}
// Next batch should start with the overflow row
{
rsLoader.startBatch();
assertEquals(1, rootWriter.rowCount());
assertEquals(expectedCount + 1, rsLoader.totalRowCount());
VectorContainer container = rsLoader.harvest();
BatchValidator.validate(container);
RowSet result = fixture.wrap(container);
assertEquals(1, result.rowCount());
result.clear();
}
rsLoader.close();
}
use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderOverflow method testArrayOverflowWithOtherArrays.
/**
* Test the complete set of array overflow cases:
* <ul>
* <li>Array a is written before the column that has overflow,
* and must be copied, in its entirety, to the overflow row.</li>
* <li>Column b causes the overflow.</li>
* <li>Column c is written after the overflow, and should go
* to the look-ahead row.</li>
* <li>Column d is written for a while, then has empties before
* the overflow row, but is written in the overflow row.<li>
* <li>Column e is like d, but is not written in the overflow
* row.</li>
*/
@Test
public void testArrayOverflowWithOtherArrays() {
TupleMetadata schema = new SchemaBuilder().addArray("a", MinorType.INT).addArray("b", MinorType.VARCHAR).addArray("c", MinorType.INT).addArray("d", MinorType.INT).buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().rowCountLimit(ValueVector.MAX_ROW_COUNT).readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Fill batch with rows of with a single array, three values each. Tack on
// a suffix to each so we can be sure the proper data is written and moved
// to the overflow batch.
byte[] value = new byte[512];
Arrays.fill(value, (byte) 'X');
String strValue = new String(value, Charsets.UTF_8);
int aCount = 3;
int bCount = 11;
int cCount = 5;
int dCount = 7;
int cCutoff = ValueVector.MAX_BUFFER_SIZE / value.length / bCount / 2;
ScalarWriter aWriter = rootWriter.array("a").scalar();
ScalarWriter bWriter = rootWriter.array("b").scalar();
ScalarWriter cWriter = rootWriter.array("c").scalar();
ScalarWriter dWriter = rootWriter.array("d").scalar();
int count = 0;
rsLoader.startBatch();
while (rootWriter.start()) {
for (int i = 0; i < aCount; i++) {
aWriter.setInt(count * aCount + i);
}
for (int i = 0; i < bCount; i++) {
String cellValue = strValue + (count * bCount + i);
bWriter.setString(cellValue);
}
if (count < cCutoff) {
for (int i = 0; i < cCount; i++) {
cWriter.setInt(count * cCount + i);
}
}
if (count < cCutoff || rootWriter.isFull()) {
for (int i = 0; i < dCount; i++) {
dWriter.setInt(count * dCount + i);
}
}
rootWriter.save();
count++;
}
// Verify
{
VectorContainer container = rsLoader.harvest();
BatchValidator.validate(container);
RowSet result = fixture.wrap(container);
assertEquals(count - 1, result.rowCount());
RowSetReader reader = result.reader();
ArrayReader aArray = reader.array("a");
ScalarReader aReader = aArray.scalar();
ArrayReader bArray = reader.array("b");
ScalarReader bReader = bArray.scalar();
ArrayReader cArray = reader.array("c");
ScalarReader cReader = cArray.scalar();
ArrayReader dArray = reader.array("d");
ScalarReader dReader = dArray.scalar();
while (reader.next()) {
int rowId = reader.offset();
assertEquals(aCount, aArray.size());
for (int i = 0; i < aCount; i++) {
assertTrue(aArray.next());
assertEquals(rowId * aCount + i, aReader.getInt());
}
assertEquals(bCount, bArray.size());
for (int i = 0; i < bCount; i++) {
assertTrue(bArray.next());
String cellValue = strValue + (rowId * bCount + i);
assertEquals(cellValue, bReader.getString());
}
if (rowId < cCutoff) {
assertEquals(cCount, cArray.size());
for (int i = 0; i < cCount; i++) {
assertTrue(cArray.next());
assertEquals(rowId * cCount + i, cReader.getInt());
}
assertEquals(dCount, dArray.size());
for (int i = 0; i < dCount; i++) {
assertTrue(dArray.next());
assertEquals(rowId * dCount + i, dReader.getInt());
}
} else {
assertEquals(0, cArray.size());
assertEquals(0, dArray.size());
}
}
result.clear();
}
int firstCount = count - 1;
// One row is in the batch. Write more, skipping over the
// initial few values for columns c and d. Column d has a
// roll-over value, c has an empty roll-over.
rsLoader.startBatch();
for (int j = 0; j < 5; j++) {
rootWriter.start();
for (int i = 0; i < aCount; i++) {
aWriter.setInt(count * aCount + i);
}
for (int i = 0; i < bCount; i++) {
String cellValue = strValue + (count * bCount + i);
bWriter.setString(cellValue);
}
if (j > 3) {
for (int i = 0; i < cCount; i++) {
cWriter.setInt(count * cCount + i);
}
for (int i = 0; i < dCount; i++) {
dWriter.setInt(count * dCount + i);
}
}
rootWriter.save();
count++;
}
{
VectorContainer container = rsLoader.harvest();
BatchValidator.validate(container);
RowSet result = fixture.wrap(container);
assertEquals(6, result.rowCount());
RowSetReader reader = result.reader();
ArrayReader aArray = reader.array("a");
ScalarReader aReader = aArray.scalar();
ArrayReader bArray = reader.array("b");
ScalarReader bReader = bArray.scalar();
ArrayReader cArray = reader.array("c");
ScalarReader cReader = cArray.scalar();
ArrayReader dArray = reader.array("d");
ScalarReader dReader = dArray.scalar();
int j = 0;
while (reader.next()) {
int rowId = firstCount + reader.offset();
assertEquals(aCount, aArray.size());
for (int i = 0; i < aCount; i++) {
assertTrue(aArray.next());
assertEquals("Index " + i, rowId * aCount + i, aReader.getInt());
}
assertEquals(bCount, bArray.size());
for (int i = 0; i < bCount; i++) {
assertTrue(bArray.next());
String cellValue = strValue + (rowId * bCount + i);
assertEquals(cellValue, bReader.getString());
}
if (j > 4) {
assertEquals(cCount, cArray.size());
for (int i = 0; i < cCount; i++) {
assertTrue(cArray.next());
assertEquals(rowId * cCount + i, cReader.getInt());
}
} else {
assertEquals(0, cArray.size());
}
if (j == 0 || j > 4) {
assertEquals(dCount, dArray.size());
for (int i = 0; i < dCount; i++) {
assertTrue(dArray.next());
assertEquals(rowId * dCount + i, dReader.getInt());
}
} else {
assertEquals(0, dArray.size());
}
j++;
}
result.clear();
}
rsLoader.close();
}
use of org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by apache.
the class TestResultSetLoaderLimits method testLimit1.
/**
* Pathological limit case: a single row.
*/
@Test
public void testLimit1() {
// Start with a small limit.
ResultSetOptions options = new ResultSetOptionBuilder().limit(1).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
assertTrue(rsLoader.startBatch());
assertEquals(1, rsLoader.maxBatchSize());
RowSetLoader rootWriter = rsLoader.writer();
rootWriter.addColumn(SchemaBuilder.columnSchema("s", MinorType.VARCHAR, DataMode.REQUIRED));
rootWriter.addRow("foo");
assertTrue(rootWriter.isFull());
assertFalse(rootWriter.start());
RowSet result = fixture.wrap(rsLoader.harvest());
assertEquals(1, result.rowCount());
result.clear();
assertTrue(rsLoader.atLimit());
rsLoader.close();
}
Aggregations