Search in sources :

Example 1 with FixedByteSkipListMultiValueWriter

use of com.linkedin.pinot.core.io.writer.impl.v1.FixedByteSkipListMultiValueWriter in project pinot by linkedin.

the class FixedByteSkipListSCMVWriterTest method testSingleColMultiValue.

@Test
public void testSingleColMultiValue() throws Exception {
    File file = new File("test_single_col_multi_value_writer.dat");
    file.delete();
    int rows = 100;
    int[][] data = new int[rows][];
    Random r = new Random();
    int totalNumValues = 0;
    for (int i = 0; i < rows; i++) {
        int numValues = r.nextInt(100) + 1;
        data[i] = new int[numValues];
        for (int j = 0; j < numValues; j++) {
            data[i][j] = r.nextInt();
        }
        totalNumValues += numValues;
    }
    FixedByteSkipListMultiValueWriter writer = new FixedByteSkipListMultiValueWriter(file, rows, totalNumValues, 4);
    int numChunks = writer.getNumChunks();
    int[] chunkOffsets = new int[numChunks];
    int chunkId = 0;
    int offset = 0;
    for (int i = 0; i < rows; i++) {
        writer.setIntArray(i, data[i]);
        if (i % writer.getDocsPerChunk() == 0) {
            chunkOffsets[chunkId] = offset;
            chunkId = chunkId + 1;
        }
        offset += data[i].length;
    }
    writer.close();
    DataInputStream dis = new DataInputStream(new FileInputStream(file));
    for (int i = 0; i < numChunks; i++) {
        Assert.assertEquals(dis.readInt(), chunkOffsets[i]);
    }
    int numBytesForBitmap = (totalNumValues + 7) / 8;
    byte[] bitsetBytes = new byte[numBytesForBitmap];
    dis.read(bitsetBytes);
    CustomBitSet customBit = CustomBitSet.withByteBuffer(numBytesForBitmap, ByteBuffer.wrap(bitsetBytes));
    offset = 0;
    //    System.out.println("getChunkOffsetHeaderSize:" + writer.getChunkOffsetHeaderSize());
    for (int i = 0; i < rows; i++) {
        Assert.assertTrue(customBit.isBitSet(offset));
        for (int j = 0; j < data[i].length; j++) {
            Assert.assertEquals(dis.readInt(), data[i][j]);
        }
        offset += data[i].length;
    }
    dis.close();
    file.delete();
    //    raf.close();
    customBit.close();
}
Also used : Random(java.util.Random) FixedByteSkipListMultiValueWriter(com.linkedin.pinot.core.io.writer.impl.v1.FixedByteSkipListMultiValueWriter) DataInputStream(java.io.DataInputStream) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) CustomBitSet(com.linkedin.pinot.core.util.CustomBitSet) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 2 with FixedByteSkipListMultiValueWriter

use of com.linkedin.pinot.core.io.writer.impl.v1.FixedByteSkipListMultiValueWriter 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();
}
Also used : Random(java.util.Random) PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) FixedByteMultiValueReader(com.linkedin.pinot.core.io.reader.impl.v1.FixedByteMultiValueReader) FixedByteSkipListMultiValueWriter(com.linkedin.pinot.core.io.writer.impl.v1.FixedByteSkipListMultiValueWriter) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

FixedByteSkipListMultiValueWriter (com.linkedin.pinot.core.io.writer.impl.v1.FixedByteSkipListMultiValueWriter)2 File (java.io.File)2 Random (java.util.Random)2 Test (org.testng.annotations.Test)2 FixedByteMultiValueReader (com.linkedin.pinot.core.io.reader.impl.v1.FixedByteMultiValueReader)1 PinotDataBuffer (com.linkedin.pinot.core.segment.memory.PinotDataBuffer)1 CustomBitSet (com.linkedin.pinot.core.util.CustomBitSet)1 DataInputStream (java.io.DataInputStream)1 FileInputStream (java.io.FileInputStream)1 RandomAccessFile (java.io.RandomAccessFile)1