use of org.apache.drill.exec.vector.RepeatedIntVector in project drill by apache.
the class TestValueVector method testRepeatedIntVector.
@Test
public void testRepeatedIntVector() {
final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedIntHolder.TYPE);
// Create a new value vector.
final RepeatedIntVector vector1 = new RepeatedIntVector(field, allocator);
// Populate the vector.
// some tricksy primes
final int[] values = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 27 };
final int nRecords = 7;
final int nElements = values.length;
vector1.allocateNew(nRecords, nRecords * nElements);
final RepeatedIntVector.Mutator mutator = vector1.getMutator();
for (int recordIndex = 0; recordIndex < nRecords; ++recordIndex) {
mutator.startNewValue(recordIndex);
for (int elementIndex = 0; elementIndex < nElements; ++elementIndex) {
mutator.add(recordIndex, recordIndex * values[elementIndex]);
}
}
mutator.setValueCount(nRecords);
// Verify the contents.
final RepeatedIntVector.Accessor accessor1 = vector1.getAccessor();
assertEquals(nRecords, accessor1.getValueCount());
for (int recordIndex = 0; recordIndex < nRecords; ++recordIndex) {
for (int elementIndex = 0; elementIndex < nElements; ++elementIndex) {
final int value = accessor1.get(recordIndex, elementIndex);
assertEquals(recordIndex * values[elementIndex], value);
}
}
/* TODO(cwestin)
the interface to load has changed
// Serialize, reify, and verify.
final DrillBuf[] buffers1 = vector1.getBuffers(false);
final DrillBuf buffer1 = combineBuffers(allocator, buffers1);
final RepeatedIntVector vector2 = new RepeatedIntVector(field, allocator);
vector2.load(nRecords, nRecords * nElements, buffer1);
final RepeatedIntVector.Accessor accessor2 = vector2.getAccessor();
for(int recordIndex = 0; recordIndex < nRecords; ++recordIndex) {
for(int elementIndex = 0; elementIndex < nElements; ++elementIndex) {
final int value = accessor2.get(recordIndex, elementIndex);
assertEquals(accessor1.get(recordIndex, elementIndex), value);
}
}
*/
vector1.close();
/* TODO(cwestin)
vector2.close();
buffer1.release();
*/
}
Aggregations