use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet in project drill by axbaretto.
the class TestFillEmpties method doFillEmptiesScalar.
private void doFillEmptiesScalar(MajorType majorType) {
TupleMetadata schema = new SchemaBuilder().add("a", majorType).buildSchema();
ExtendableRowSet rs = fixture.rowSet(schema);
RowSetWriter writer = rs.writer();
ScalarWriter colWriter = writer.scalar(0);
ValueType valueType = colWriter.valueType();
boolean nullable = majorType.getMode() == DataMode.OPTIONAL;
for (int i = 0; i < ROW_COUNT; i++) {
if (i % 5 == 0) {
colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i));
}
writer.save();
}
SingleRowSet result = writer.done();
RowSetReader reader = result.reader();
ScalarReader colReader = reader.scalar(0);
MinorType type = majorType.getMinorType();
boolean isVariable = (type == MinorType.VARCHAR || type == MinorType.VAR16CHAR || type == MinorType.VARBINARY);
for (int i = 0; i < ROW_COUNT; i++) {
assertTrue(reader.next());
if (i % 5 != 0) {
if (nullable) {
// Nullable types fill with nulls.
assertTrue(colReader.isNull());
continue;
}
if (isVariable) {
// Variable width types fill with a zero-length value.
assertEquals(0, colReader.getBytes().length);
continue;
}
}
// All other types fill with zero-bytes, interpreted as some form
// of zero for each type.
Object actual = colReader.getObject();
Object expected = RowSetUtilities.testDataFromInt(valueType, majorType, i % 5 == 0 ? i : 0);
RowSetUtilities.assertEqualValues(majorType.toString().replace('\n', ' ') + "[" + i + "]", valueType, expected, actual);
}
result.clear();
}
use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet in project drill by axbaretto.
the class TestCopier method makeDataSet.
public static SingleRowSet makeDataSet(BatchSchema schema, int first, int step, int count) {
ExtendableRowSet rowSet = fixture.rowSet(schema);
RowSetWriter writer = rowSet.writer(count);
int value = first;
for (int i = 0; i < count; i++, value += step) {
RowSetUtilities.setFromInt(writer, 0, value);
writer.scalar(1).setString(Integer.toString(value));
writer.save();
}
writer.done();
return rowSet;
}
use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet in project drill by axbaretto.
the class TestSortImpl method runWideRowsTest.
/**
* Run a test using wide rows. This stresses the "copier" portion of the sort
* and allows us to test the original generated copier and the revised "generic"
* copier.
*
* @param fixture operator test fixture
* @param colCount number of data (non-key) columns
* @param rowCount number of rows to generate
*/
public void runWideRowsTest(OperatorFixture fixture, int colCount, int rowCount) {
SchemaBuilder builder = new SchemaBuilder().add("key", MinorType.INT);
for (int i = 0; i < colCount; i++) {
builder.add("col" + (i + 1), MinorType.INT);
}
BatchSchema schema = builder.build();
ExtendableRowSet rowSet = fixture.rowSet(schema);
RowSetWriter writer = rowSet.writer(rowCount);
for (int i = 0; i < rowCount; i++) {
writer.set(0, i);
for (int j = 0; j < colCount; j++) {
writer.set(j + 1, i * 100_000 + j);
}
writer.save();
}
writer.done();
VectorContainer dest = new VectorContainer();
SortImpl sort = makeSortImpl(fixture, Ordering.ORDER_ASC, Ordering.NULLS_UNSPECIFIED, dest);
sort.setSchema(rowSet.container().getSchema());
sort.addBatch(rowSet.vectorAccessible());
SortResults results = sort.startMerge();
if (results.getContainer() != dest) {
dest.clear();
dest = results.getContainer();
}
assertTrue(results.next());
assertFalse(results.next());
results.close();
dest.clear();
sort.close();
sort.opContext().close();
}
use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet in project drill by axbaretto.
the class TestBatchSerialization method makeRowSet.
public SingleRowSet makeRowSet(BatchSchema schema, int rowCount) {
ExtendableRowSet rowSet = fixture.rowSet(schema);
RowSetWriter writer = rowSet.writer(rowCount);
for (int i = 0; i < rowCount; i++) {
RowSetUtilities.setFromInt(writer, 0, i);
writer.save();
}
writer.done();
return rowSet;
}
use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet in project drill by axbaretto.
the class RowSetTest method testTopFixedWidthArray.
/**
* Test an array of ints (as an example fixed-width type)
* at the top level of a schema.
*/
@Test
public void testTopFixedWidthArray() {
BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).addArray("a", MinorType.INT).build();
ExtendableRowSet rs1 = fixture.rowSet(batchSchema);
RowSetWriter writer = rs1.writer();
writer.scalar(0).setInt(10);
ScalarWriter array = writer.array(1).scalar();
array.setInt(100);
array.setInt(110);
writer.save();
writer.scalar(0).setInt(20);
array.setInt(200);
array.setInt(120);
array.setInt(220);
writer.save();
writer.scalar(0).setInt(30);
writer.save();
SingleRowSet result = writer.done();
RowSetReader reader = result.reader();
assertTrue(reader.next());
assertEquals(10, reader.scalar(0).getInt());
ScalarElementReader arrayReader = reader.array(1).elements();
assertEquals(2, arrayReader.size());
assertEquals(100, arrayReader.getInt(0));
assertEquals(110, arrayReader.getInt(1));
assertTrue(reader.next());
assertEquals(20, reader.scalar(0).getInt());
assertEquals(3, arrayReader.size());
assertEquals(200, arrayReader.getInt(0));
assertEquals(120, arrayReader.getInt(1));
assertEquals(220, arrayReader.getInt(2));
assertTrue(reader.next());
assertEquals(30, reader.scalar(0).getInt());
assertEquals(0, arrayReader.size());
assertFalse(reader.next());
SingleRowSet rs2 = fixture.rowSetBuilder(batchSchema).addRow(10, intArray(100, 110)).addRow(20, intArray(200, 120, 220)).addRow(30, null).build();
new RowSetComparison(rs1).verifyAndClearAll(rs2);
}
Aggregations