Search in sources :

Example 11 with PinotDataBuffer

use of com.linkedin.pinot.core.segment.memory.PinotDataBuffer in project pinot by linkedin.

the class FixedBitWidthRowColDataFileReaderTest method testSingleColUnsigned.

/**
   * Tests only positive numbers
   *
   * @throws Exception
   */
@Test
public void testSingleColUnsigned() throws Exception {
    int[] maxBitArray = new int[] { 4 };
    for (int maxBits : maxBitArray) {
        String fileName = "test" + maxBits + "FixedBitWidthSingleCol";
        File file = new File(fileName);
        CustomBitSet bitset = null;
        try {
            //        System.out.println("START MAX BITS:" + maxBits);
            int numElements = 100;
            bitset = CustomBitSet.withBitLength(numElements * maxBits);
            int max = (int) Math.pow(2, maxBits);
            Random r = new Random();
            int[] values = new int[numElements];
            for (int i = 0; i < numElements; i++) {
                int value = r.nextInt(max);
                values[i] = value;
                for (int j = maxBits - 1; j >= 0; j--) {
                    if ((value & (1 << j)) != 0) {
                        bitset.setBit(i * maxBits + (maxBits - j - 1));
                    }
                }
            }
            byte[] byteArray = bitset.toByteArray();
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(byteArray);
            fos.close();
            PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(file, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "testing");
            FixedBitSingleValueMultiColReader heapReader = new FixedBitSingleValueMultiColReader(heapBuffer, numElements, 1, new int[] { maxBits });
            for (int i = 0; i < numElements; i++) {
                int readInt = heapReader.getInt(i, 0);
                Assert.assertEquals(readInt, values[i]);
            }
            heapReader.close();
            heapBuffer.close();
            PinotDataBuffer dataBuffer = PinotDataBuffer.fromFile(file, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, "mmap-testing");
            FixedBitSingleValueMultiColReader mmapReader = new FixedBitSingleValueMultiColReader(dataBuffer, numElements, 1, new int[] { maxBits });
            for (int i = 0; i < numElements; i++) {
                int readInt = mmapReader.getInt(i, 0);
                Assert.assertEquals(readInt, values[i]);
            }
            mmapReader.close();
            dataBuffer.close();
        //        System.out.println("END MAX BITS:" + maxBits);
        } finally {
            file.delete();
            bitset.close();
        }
    }
}
Also used : Random(java.util.Random) PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) FixedBitSingleValueMultiColReader(com.linkedin.pinot.core.io.reader.impl.FixedBitSingleValueMultiColReader) FileOutputStream(java.io.FileOutputStream) File(java.io.File) CustomBitSet(com.linkedin.pinot.core.util.CustomBitSet) Test(org.testng.annotations.Test)

Example 12 with PinotDataBuffer

use of com.linkedin.pinot.core.segment.memory.PinotDataBuffer in project pinot by linkedin.

the class ColumnIndexDirectoryTestHelper method newIndexBuffer.

static PinotDataBuffer newIndexBuffer(ColumnIndexDirectory columnDirectory, String column, int size, int index) throws IOException {
    String columnName = column + "." + Integer.toString(index);
    // skip star tree. It's managed differently
    ColumnIndexType indexType = indexTypes[index % indexTypes.length];
    PinotDataBuffer buf = null;
    switch(indexType) {
        case DICTIONARY:
            buf = columnDirectory.newDictionaryBuffer(columnName, size);
            break;
        case FORWARD_INDEX:
            buf = columnDirectory.newForwardIndexBuffer(columnName, size);
            break;
        case INVERTED_INDEX:
            buf = columnDirectory.newInvertedIndexBuffer(columnName, size);
            break;
    }
    return buf;
}
Also used : PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) Matchers.anyString(org.mockito.Matchers.anyString)

Example 13 with PinotDataBuffer

use of com.linkedin.pinot.core.segment.memory.PinotDataBuffer in project pinot by linkedin.

the class ColumnIndexDirectoryTestHelper method getIndexBuffer.

static PinotDataBuffer getIndexBuffer(ColumnIndexDirectory columnDirectory, String column, int index) throws IOException {
    String columnName = column + "." + Integer.toString(index);
    // skip star tree
    ColumnIndexType indexType = indexTypes[index % indexTypes.length];
    PinotDataBuffer buf = null;
    switch(indexType) {
        case DICTIONARY:
            buf = columnDirectory.getDictionaryBufferFor(columnName);
            break;
        case FORWARD_INDEX:
            buf = columnDirectory.getForwardIndexBufferFor(columnName);
            break;
        case INVERTED_INDEX:
            buf = columnDirectory.getInvertedIndexBufferFor(columnName);
            break;
    }
    return buf;
}
Also used : PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) Matchers.anyString(org.mockito.Matchers.anyString)

Example 14 with PinotDataBuffer

use of com.linkedin.pinot.core.segment.memory.PinotDataBuffer in project pinot by linkedin.

the class FilePerIndexDirectoryTest method testHasIndex.

@Test
public void testHasIndex() throws IOException {
    try (FilePerIndexDirectory fpiDirectory = new FilePerIndexDirectory(segmentDir, segmentMetadata, ReadMode.mmap)) {
        PinotDataBuffer buffer = fpiDirectory.newDictionaryBuffer("foo", 1024);
        buffer.putInt(0, 100);
        Assert.assertTrue(fpiDirectory.hasIndexFor("foo", ColumnIndexType.DICTIONARY));
    }
}
Also used : PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) Test(org.testng.annotations.Test)

Example 15 with PinotDataBuffer

use of com.linkedin.pinot.core.segment.memory.PinotDataBuffer in project pinot by linkedin.

the class SingleFileIndexDirectoryTest method testRemoveIndex.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testRemoveIndex() throws IOException, ConfigurationException {
    try (SingleFileIndexDirectory sfd = new SingleFileIndexDirectory(segmentDir, segmentMetadata, ReadMode.mmap)) {
        try (PinotDataBuffer buffer = sfd.newDictionaryBuffer("col1", 1024)) {
        }
        Assert.assertFalse(sfd.isIndexRemovalSupported());
        sfd.removeIndex("col1", ColumnIndexType.DICTIONARY);
    }
}
Also used : PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) Test(org.testng.annotations.Test)

Aggregations

PinotDataBuffer (com.linkedin.pinot.core.segment.memory.PinotDataBuffer)56 File (java.io.File)29 Test (org.testng.annotations.Test)27 Random (java.util.Random)16 FixedByteSingleValueMultiColReader (com.linkedin.pinot.core.io.reader.impl.FixedByteSingleValueMultiColReader)11 FixedByteSingleValueMultiColWriter (com.linkedin.pinot.core.io.writer.impl.FixedByteSingleValueMultiColWriter)8 ChunkDecompressor (com.linkedin.pinot.core.io.compression.ChunkDecompressor)6 ChunkReaderContext (com.linkedin.pinot.core.io.reader.impl.ChunkReaderContext)6 RandomAccessFile (java.io.RandomAccessFile)6 ChunkCompressor (com.linkedin.pinot.core.io.compression.ChunkCompressor)5 FixedByteChunkSingleValueReader (com.linkedin.pinot.core.io.reader.impl.v1.FixedByteChunkSingleValueReader)5 ColumnMetadata (com.linkedin.pinot.core.segment.index.ColumnMetadata)5 SegmentMetadataImpl (com.linkedin.pinot.core.segment.index.SegmentMetadataImpl)5 BitmapInvertedIndexReader (com.linkedin.pinot.core.segment.index.readers.BitmapInvertedIndexReader)5 SegmentDirectory (com.linkedin.pinot.core.segment.store.SegmentDirectory)5 FileOutputStream (java.io.FileOutputStream)5 FixedByteChunkSingleValueWriter (com.linkedin.pinot.core.io.writer.impl.v1.FixedByteChunkSingleValueWriter)4 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)4 FixedBitSingleValueMultiColReader (com.linkedin.pinot.core.io.reader.impl.FixedBitSingleValueMultiColReader)3 SingleColumnMultiValueWriter (com.linkedin.pinot.core.io.writer.SingleColumnMultiValueWriter)3