use of org.apache.drill.exec.physical.rowSet.impl.ResultSetLoaderImpl.ResultSetOptions in project drill by axbaretto.
the class TestResultSetLoaderLimits method testCustomRowLimit.
/**
* Verify that the caller can set a row limit lower than the default.
*/
@Test
public void testCustomRowLimit() {
// Try to set a default value larger than the hard limit. Value
// is truncated to the limit.
ResultSetOptions options = new OptionBuilder().setRowCountLimit(ValueVector.MAX_ROW_COUNT + 1).build();
assertEquals(ValueVector.MAX_ROW_COUNT, options.rowCountLimit);
// Just a bit of paranoia that we check against the vector limit,
// not any previous value...
options = new OptionBuilder().setRowCountLimit(ValueVector.MAX_ROW_COUNT + 1).setRowCountLimit(TEST_ROW_LIMIT).build();
assertEquals(TEST_ROW_LIMIT, options.rowCountLimit);
options = new OptionBuilder().setRowCountLimit(TEST_ROW_LIMIT).setRowCountLimit(ValueVector.MAX_ROW_COUNT + 1).build();
assertEquals(ValueVector.MAX_ROW_COUNT, options.rowCountLimit);
// Can't set the limit lower than 1
options = new OptionBuilder().setRowCountLimit(0).build();
assertEquals(1, options.rowCountLimit);
// Do load with a (valid) limit lower than the default.
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());
// Should fail to write beyond the row limit
assertFalse(rootWriter.start());
try {
rootWriter.save();
fail();
} catch (IllegalStateException e) {
// Expected
}
rsLoader.harvest().clear();
rsLoader.startBatch();
assertEquals(0, rootWriter.rowCount());
rsLoader.close();
}
Aggregations