use of com.linkedin.pinot.core.io.reader.impl.v1.FixedByteMultiValueReader in project pinot by linkedin.
the class FixedByteSkipListSCMVReaderTest method testSingleColMultiValue.
@Test
public void testSingleColMultiValue() throws Exception {
String fileName = "test_single_col.dat";
File f = new File(fileName);
f.delete();
int numDocs = 100;
int maxMultiValues = 100;
int[][] data = new int[numDocs][];
Random r = new Random();
int totalNumValues = 0;
int[] startOffsets = new int[numDocs];
int[] lengths = new int[numDocs];
for (int i = 0; i < data.length; i++) {
int numValues = r.nextInt(maxMultiValues) + 1;
data[i] = new int[numValues];
for (int j = 0; j < numValues; j++) {
data[i][j] = r.nextInt();
}
startOffsets[i] = totalNumValues;
lengths[i] = numValues;
totalNumValues = totalNumValues + numValues;
}
for (int i = 0; i < data.length; i++) {
LOGGER.trace("(" + i + "," + startOffsets[i] + "," + lengths[i] + ")");
LOGGER.trace(",");
}
LOGGER.trace(Arrays.toString(startOffsets));
LOGGER.trace(Arrays.toString(lengths));
FixedByteSkipListMultiValueWriter writer = new FixedByteSkipListMultiValueWriter(f, numDocs, totalNumValues, Integer.SIZE / 8);
for (int i = 0; i < data.length; i++) {
writer.setIntArray(i, data[i]);
}
writer.close();
int[] readValues = new int[maxMultiValues];
PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(f, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "heap-testing");
FixedByteMultiValueReader heapReader = new FixedByteMultiValueReader(heapBuffer, numDocs, totalNumValues, Integer.SIZE / 8);
for (int i = 0; i < data.length; i++) {
int numValues = heapReader.getIntArray(i, readValues);
Assert.assertEquals(numValues, data[i].length);
for (int j = 0; j < numValues; j++) {
Assert.assertEquals(readValues[j], data[i][j], "");
}
}
heapReader.close();
heapBuffer.close();
PinotDataBuffer mmapBuffer = PinotDataBuffer.fromFile(f, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, "mmap-testing");
FixedByteMultiValueReader mmapReader = new FixedByteMultiValueReader(mmapBuffer, numDocs, totalNumValues, Integer.SIZE / 8);
for (int i = 0; i < data.length; i++) {
int numValues = mmapReader.getIntArray(i, readValues);
Assert.assertEquals(numValues, data[i].length);
for (int j = 0; j < numValues; j++) {
Assert.assertEquals(readValues[j], data[i][j], "");
}
}
mmapReader.close();
mmapBuffer.close();
f.delete();
}
Aggregations