Search in sources :

Example 1 with VSizeIndexedInts

use of io.druid.segment.data.VSizeIndexedInts in project druid by druid-io.

the class CompressedVSizeIndexedBenchmark method setup.

@Setup
public void setup() throws IOException {
    Random rand = new Random(0);
    List<int[]> rows = Lists.newArrayList();
    final int bound = 1 << bytes;
    for (int i = 0; i < 0x100000; i++) {
        int count = rand.nextInt(valuesPerRowBound) + 1;
        int[] row = new int[rand.nextInt(count)];
        for (int j = 0; j < row.length; j++) {
            row[j] = rand.nextInt(bound);
        }
        rows.add(row);
    }
    final ByteBuffer bufferCompressed = serialize(CompressedVSizeIndexedSupplier.fromIterable(Iterables.transform(rows, new Function<int[], IndexedInts>() {

        @Override
        public IndexedInts apply(int[] input) {
            return VSizeIndexedInts.fromArray(input, 20);
        }
    }), bound - 1, ByteOrder.nativeOrder(), CompressedObjectStrategy.CompressionStrategy.LZ4));
    this.compressed = CompressedVSizeIndexedSupplier.fromByteBuffer(bufferCompressed, ByteOrder.nativeOrder(), null).get();
    final ByteBuffer bufferUncompressed = serialize(VSizeIndexed.fromIterable(Iterables.transform(rows, new Function<int[], VSizeIndexedInts>() {

        @Override
        public VSizeIndexedInts apply(int[] input) {
            return VSizeIndexedInts.fromArray(input, 20);
        }
    })).asWritableSupplier());
    this.uncompressed = VSizeIndexed.readFromByteBuffer(bufferUncompressed);
    filter = new BitSet();
    for (int i = 0; i < filteredRowCount; i++) {
        int rowToAccess = rand.nextInt(rows.size());
        // Skip already selected rows if any
        while (filter.get(rowToAccess)) {
            rowToAccess = (rowToAccess + 1) % rows.size();
        }
        filter.set(rowToAccess);
    }
}
Also used : Function(com.google.common.base.Function) Random(java.util.Random) VSizeIndexedInts(io.druid.segment.data.VSizeIndexedInts) IndexedInts(io.druid.segment.data.IndexedInts) BitSet(java.util.BitSet) ByteBuffer(java.nio.ByteBuffer) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

Function (com.google.common.base.Function)1 IndexedInts (io.druid.segment.data.IndexedInts)1 VSizeIndexedInts (io.druid.segment.data.VSizeIndexedInts)1 ByteBuffer (java.nio.ByteBuffer)1 BitSet (java.util.BitSet)1 Random (java.util.Random)1 Setup (org.openjdk.jmh.annotations.Setup)1