use of org.apache.drill.exec.vector.accessor.ValueType in project drill by axbaretto.
the class TestFillEmpties method dofillEmptiesRepeated.
private void dofillEmptiesRepeated(MajorType majorType) {
TupleMetadata schema = new SchemaBuilder().add("a", majorType).buildSchema();
ExtendableRowSet rs = fixture.rowSet(schema);
RowSetWriter writer = rs.writer();
ScalarWriter colWriter = writer.array(0).scalar();
ValueType valueType = colWriter.valueType();
for (int i = 0; i < ROW_COUNT; i++) {
if (i % 5 == 0) {
// Write two values so we can exercise a bit of the array logic.
colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i));
colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i + 1));
}
writer.save();
}
SingleRowSet result = writer.done();
RowSetReader reader = result.reader();
ScalarElementReader colReader = reader.array(0).elements();
for (int i = 0; i < ROW_COUNT; i++) {
assertTrue(reader.next());
if (i % 5 != 0) {
// Empty arrays are defined to be the same as a zero-length array.
assertEquals(0, colReader.size());
} else {
for (int j = 0; j < 2; j++) {
Object actual = colReader.getObject(j);
Object expected = RowSetUtilities.testDataFromInt(valueType, majorType, i + j);
RowSetUtilities.assertEqualValues(majorType.toString().replace('\n', ' ') + "[" + i + "][" + j + "]", valueType, expected, actual);
}
}
}
result.clear();
}
use of org.apache.drill.exec.vector.accessor.ValueType in project drill by apache.
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 = Types.isVarWidthType(type);
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();
}
Aggregations