use of org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet in project drill by apache.
the class TestFillEmpties method testBitFillEmpties.
/**
* Bit vector is special; packs 8 values per byte. Use custom
* logic to ship entire bytes.
*/
@Test
public void testBitFillEmpties() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.BIT).buildSchema();
ExtendableRowSet rs = fixture.rowSet(schema);
RowSetWriter writer = rs.writer();
ScalarWriter colWriter = writer.scalar(0);
for (int i = 0; i < ROW_COUNT; i++) {
if (i % 43 == 0) {
colWriter.setInt(1);
}
writer.save();
}
SingleRowSet result = writer.done();
RowSetReader reader = result.reader();
ScalarReader colReader = reader.scalar(0);
for (int i = 0; i < ROW_COUNT; i++) {
assertTrue(reader.next());
assertEquals(i % 43 == 0 ? 1 : 0, colReader.getInt());
}
result.clear();
}
use of org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet 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();
}
use of org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet in project drill by apache.
the class TestIndirectReaders method testRequired.
/**
* Simplest case: required reader, uses the index
* directly.
*/
@Test
public void testRequired() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
ExtendableRowSet rowSet = fixture.rowSet(schema);
RowSetWriter writer = rowSet.writer();
for (int i = 0; i < 10; i++) {
writer.scalar(0).setInt(i);
writer.save();
}
SingleRowSet result = writer.done().toIndirect();
// Use the SV2 to reverse the row order.
SelectionVector2 sv2 = result.getSv2();
for (int i = 0; i < 10; i++) {
sv2.setIndex(i, 9 - i);
}
// Values should be read back in the reverse order.
RowSetReader reader = result.reader();
for (int i = 9; i >= 0; i--) {
assertTrue(reader.next());
assertEquals(i, reader.scalar(0).getInt());
}
// The row set comparison should read using the
// indirection.
SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(9).addRow(8).addRow(7).addRow(6).addRow(5).addRow(4).addRow(3).addRow(2).addRow(1).addRow(0).build();
RowSetUtilities.verify(expected, result);
}
use of org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet in project drill by apache.
the class TestRowSet method testRepeatedDictStructure.
@Test
public void testRepeatedDictStructure() {
final String dictName = "d";
final TupleMetadata schema = new SchemaBuilder().add("id", MinorType.INT).addDictArray(dictName, MinorType.FLOAT8).value(MinorType.VARCHAR).resumeSchema().buildSchema();
final ExtendableRowSet rowSet = fixture.rowSet(schema);
final RowSetWriter writer = rowSet.writer();
// Repeated dict
assertEquals(ObjectType.ARRAY, writer.column(dictName).type());
final ScalarWriter idWriter = writer.scalar(0);
final ArrayWriter dictArrayWriter = writer.column(1).array();
assertEquals(ObjectType.ARRAY, dictArrayWriter.entryType());
DictWriter dictWriter = dictArrayWriter.dict();
assertEquals(ValueType.DOUBLE, dictWriter.keyType());
assertEquals(ObjectType.SCALAR, dictWriter.valueType());
final ScalarWriter keyWriter = dictWriter.keyWriter();
final ScalarWriter valueWriter = dictWriter.valueWriter().scalar();
assertEquals(ValueType.DOUBLE, keyWriter.valueType());
assertEquals(ValueType.STRING, valueWriter.valueType());
// Write data
idWriter.setInt(1);
keyWriter.setDouble(1);
valueWriter.setString("a");
// advance to next entry position
dictWriter.save();
keyWriter.setDouble(2);
valueWriter.setString("b");
dictWriter.save();
// advance to next array position
dictArrayWriter.save();
keyWriter.setDouble(3);
valueWriter.setString("c");
dictWriter.save();
dictArrayWriter.save();
// advance to next row
writer.save();
idWriter.setInt(2);
keyWriter.setDouble(11);
valueWriter.setString("d");
dictWriter.save();
keyWriter.setDouble(12);
valueWriter.setString("e");
dictWriter.save();
dictArrayWriter.save();
writer.save();
idWriter.setInt(3);
keyWriter.setDouble(21);
valueWriter.setString("f");
dictWriter.save();
keyWriter.setDouble(22);
valueWriter.setString("g");
dictWriter.save();
keyWriter.setDouble(23);
valueWriter.setString("h");
dictWriter.save();
dictArrayWriter.save();
keyWriter.setDouble(24);
valueWriter.setString("i");
dictWriter.save();
keyWriter.setDouble(25);
valueWriter.setString("j");
dictWriter.save();
keyWriter.setDouble(26.5);
valueWriter.setString("k");
dictWriter.save();
keyWriter.setDouble(27);
valueWriter.setString("l");
dictWriter.save();
keyWriter.setDouble(28);
valueWriter.setString("m");
dictWriter.save();
dictArrayWriter.save();
writer.save();
// Finish the row set and get a reader.
final SingleRowSet actual = writer.done();
final RowSetReader reader = actual.reader();
// Verify reader structure
assertEquals(ObjectType.ARRAY, reader.column(dictName).type());
final ArrayReader dictArrayReader = reader.array(1);
assertEquals(ObjectType.ARRAY, dictArrayReader.entryType());
final DictReader dictReader = dictArrayReader.entry().dict();
assertEquals(ValueType.DOUBLE, dictReader.keyColumnType());
assertEquals(ObjectType.SCALAR, dictReader.valueColumnType());
final KeyAccessor keyAccessor = dictReader.keyAccessor();
final ScalarReader valueReader = dictReader.valueReader().scalar();
// Row 1
assertTrue(reader.next());
// array is not null
assertFalse(dictArrayReader.isNull());
assertTrue(dictArrayReader.next());
// first dict is not null
assertFalse(dictArrayReader.isNull());
assertTrue(keyAccessor.find(2.0f));
assertEquals("b", valueReader.getObject());
assertTrue(keyAccessor.find(1.0f));
assertEquals("a", valueReader.getObject());
// no entry for given key
assertFalse(keyAccessor.find(1.1f));
assertTrue(dictArrayReader.next());
assertTrue(keyAccessor.find(3.0f));
assertEquals("c", valueReader.getObject());
assertFalse(keyAccessor.find(1.0f));
assertEquals(Arrays.asList(map(1.0, "a", 2.0, "b"), map(3.0, "c")), dictArrayReader.getObject());
// Row 2
assertTrue(reader.next());
assertTrue(dictArrayReader.next());
assertTrue(keyAccessor.find(11.0f));
assertEquals("d", valueReader.getString());
assertFalse(keyAccessor.find(1.0f));
assertTrue(keyAccessor.find(12.0f));
assertEquals("e", valueReader.getString());
// Row 3: use explicit positioning
assertTrue(reader.next());
dictArrayReader.setPosn(1);
assertTrue(keyAccessor.find(24.0f));
assertEquals("i", valueReader.getString());
assertTrue(keyAccessor.find(26.5f));
assertEquals("k", valueReader.getString());
assertTrue(keyAccessor.find(28.0f));
assertEquals("m", valueReader.getString());
assertFalse(keyAccessor.find(35.0f));
assertTrue(keyAccessor.find(27.0f));
assertEquals("l", valueReader.getString());
Map<Object, Object> element1 = map(24.0, "i", 25.0, "j", 26.5, "k", 27.0, "l", 28.0, "m");
assertEquals(element1, dictReader.getObject());
dictArrayReader.setPosn(0);
assertTrue(keyAccessor.find(23.0f));
assertEquals("h", valueReader.getObject());
assertTrue(keyAccessor.find(21.0f));
assertEquals("f", valueReader.getObject());
assertFalse(keyAccessor.find(23.05f));
Map<Object, Object> element0 = map(21.0, "f", 22.0, "g", 23.0, "h");
assertEquals(element0, dictReader.getObject());
assertEquals(Arrays.asList(element0, element1), dictArrayReader.getObject());
assertFalse(reader.next());
// Verify that the dict accessor's value count was set.
final RepeatedDictVector vector = (RepeatedDictVector) actual.container().getValueVector(1).getValueVector();
assertEquals(3, vector.getAccessor().getValueCount());
final SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(1, objArray(map(1.0f, "a", 2.0f, "b"), map(3.0f, "c"))).addRow(2, objArray(singleObjArray(map(11.0f, "d", 12.0f, "e")))).addRow(3, objArray(map(21.0f, "f", 22.0f, "g", 23.0f, "h"), map(24.0f, "i", 25.0f, "j", 26.5f, "k", 27.0f, "l", 28.0f, "m"))).build();
RowSetUtilities.verify(expected, actual);
}
use of org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet in project drill by apache.
the class TestRowSet method testBufferBounds.
/**
* Test filling a row set up to the maximum vector size.
* Values in the first column are small enough to prevent filling to the
* maximum buffer size, but values in the second column
* will reach maximum buffer size before maximum row size.
* The result should be the number of rows that fit, with the
* partial last row not counting. (A complete application would
* reload the partial row into a new row set.)
*/
@Test
public void testBufferBounds() {
final TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
String varCharValue;
try {
final byte[] rawValue = new byte[512];
Arrays.fill(rawValue, (byte) 'X');
varCharValue = new String(rawValue, "UTF-8");
} catch (final UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
final ExtendableRowSet rs = fixture.rowSet(schema);
final RowSetWriter writer = rs.writer();
int count = 0;
try {
while (true) {
writer.scalar(0).setInt(count);
writer.scalar(1).setString(varCharValue);
// Won't get here on overflow.
writer.save();
count++;
}
} catch (final Exception e) {
assertTrue(e.getMessage().contains("Overflow"));
}
writer.done();
assertTrue(count < ValueVector.MAX_ROW_COUNT);
assertEquals(count, writer.rowIndex());
assertEquals(count, rs.rowCount());
rs.clear();
}
Aggregations