Search in sources :

Example 16 with ResultSetOptions

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();
}
Also used : ResultSetLoader(org.apache.drill.exec.physical.rowSet.ResultSetLoader) RowSetLoader(org.apache.drill.exec.physical.rowSet.RowSetLoader) ResultSetOptions(org.apache.drill.exec.physical.rowSet.impl.ResultSetLoaderImpl.ResultSetOptions) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)16 ResultSetOptions (org.apache.drill.exec.physical.rowSet.impl.ResultSetLoaderImpl.ResultSetOptions)16 SubOperatorTest (org.apache.drill.test.SubOperatorTest)16 Test (org.junit.Test)16 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)15 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)13 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)12 RowSet (org.apache.drill.test.rowSet.RowSet)9 SchemaPath (org.apache.drill.common.expression.SchemaPath)5 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)5 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)4 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)4 BatchSchema (org.apache.drill.exec.record.BatchSchema)3 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)3 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)2 UserException (org.apache.drill.common.exceptions.UserException)1 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)1