Search in sources :

Example 1 with FixedBitSingleValueWriter

use of com.linkedin.pinot.core.io.writer.impl.v2.FixedBitSingleValueWriter in project pinot by linkedin.

the class FixedBitSingleValueTest method testV2.

@Test
public void testV2() throws Exception {
    int ROWS = 1000;
    for (int numBits = 1; numBits < 32; numBits++) {
        File file = new File(this.getClass().getName() + "_" + numBits + ".test");
        FixedBitSingleValueWriter writer = new FixedBitSingleValueWriter(file, ROWS, numBits);
        int[] data = new int[ROWS];
        Random random = new Random();
        int max = (int) Math.pow(2, numBits);
        for (int i = 0; i < ROWS; i++) {
            data[i] = random.nextInt(max);
            writer.setInt(i, data[i]);
        }
        writer.close();
        PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(file, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "testing");
        FixedBitSingleValueReader reader = new FixedBitSingleValueReader(heapBuffer, ROWS, numBits);
        int[] read = new int[ROWS];
        for (int i = 0; i < ROWS; i++) {
            read[i] = reader.getInt(i);
        //Assert.assertEquals(reader.getInt(i), data[i],
        //  "Failed for bit:" + numBits + " Expected " + data[i] + " but found " + reader.getInt(i) + "  at " + i);
        }
        LOGGER.trace(Arrays.toString(data));
        LOGGER.trace(Arrays.toString(read));
        reader.close();
        heapBuffer.close();
        file.delete();
    }
}
Also used : Random(java.util.Random) PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) FixedBitSingleValueWriter(com.linkedin.pinot.core.io.writer.impl.v2.FixedBitSingleValueWriter) FixedBitSingleValueReader(com.linkedin.pinot.core.io.reader.impl.v2.FixedBitSingleValueReader) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

FixedBitSingleValueReader (com.linkedin.pinot.core.io.reader.impl.v2.FixedBitSingleValueReader)1 FixedBitSingleValueWriter (com.linkedin.pinot.core.io.writer.impl.v2.FixedBitSingleValueWriter)1 PinotDataBuffer (com.linkedin.pinot.core.segment.memory.PinotDataBuffer)1 File (java.io.File)1 Random (java.util.Random)1 Test (org.testng.annotations.Test)1