Search in sources :

Example 6 with FileSmoosher

use of io.druid.java.util.common.io.smoosh.FileSmoosher in project druid by druid-io.

the class CompressedIntsIndexedWriterTest method checkV2SerializedSizeAndData.

private void checkV2SerializedSizeAndData(int chunkFactor) throws Exception {
    File tmpDirectory = Files.createTempDirectory(String.format("CompressedIntsIndexedWriterTest_%d", chunkFactor)).toFile();
    FileSmoosher smoosher = new FileSmoosher(tmpDirectory);
    final IOPeon ioPeon = new TmpFileIOPeon();
    try {
        CompressedIntsIndexedWriter writer = new CompressedIntsIndexedWriter(chunkFactor, compressionStrategy, new GenericIndexedWriter<>(ioPeon, "test", CompressedIntBufferObjectStrategy.getBufferForOrder(byteOrder, compressionStrategy, chunkFactor), Longs.BYTES * 10000));
        writer.open();
        for (int val : vals) {
            writer.add(val);
        }
        writer.close();
        final SmooshedWriter channel = smoosher.addWithSmooshedWriter("test", writer.getSerializedSize());
        writer.writeToChannel(channel, smoosher);
        channel.close();
        smoosher.close();
        SmooshedFileMapper mapper = Smoosh.map(tmpDirectory);
        // read from ByteBuffer and check values
        CompressedIntsIndexedSupplier supplierFromByteBuffer = CompressedIntsIndexedSupplier.fromByteBuffer(mapper.mapFile("test"), byteOrder, mapper);
        IndexedInts indexedInts = supplierFromByteBuffer.get();
        assertEquals(vals.length, indexedInts.size());
        for (int i = 0; i < vals.length; ++i) {
            assertEquals(vals[i], indexedInts.get(i));
        }
        CloseQuietly.close(indexedInts);
        mapper.close();
    } finally {
        ioPeon.close();
    }
}
Also used : SmooshedWriter(io.druid.java.util.common.io.smoosh.SmooshedWriter) FileSmoosher(io.druid.java.util.common.io.smoosh.FileSmoosher) File(java.io.File) SmooshedFileMapper(io.druid.java.util.common.io.smoosh.SmooshedFileMapper)

Example 7 with FileSmoosher

use of io.druid.java.util.common.io.smoosh.FileSmoosher in project druid by druid-io.

the class CompressedVSizeIndexedV3WriterTest method checkSerializedSizeAndData.

private void checkSerializedSizeAndData(int offsetChunkFactor, int valueChunkFactor) throws Exception {
    FileSmoosher smoosher = new FileSmoosher(FileUtils.getTempDirectory());
    final IOPeon ioPeon = new TmpFileIOPeon();
    final IndexedMultivalue<IndexedInts> indexedMultivalue;
    try {
        int maxValue = vals.size() > 0 ? getMaxValue(vals) : 0;
        CompressedIntsIndexedWriter offsetWriter = new CompressedIntsIndexedWriter(ioPeon, "offset", offsetChunkFactor, byteOrder, compressionStrategy);
        CompressedVSizeIntsIndexedWriter valueWriter = new CompressedVSizeIntsIndexedWriter(ioPeon, "value", maxValue, valueChunkFactor, byteOrder, compressionStrategy);
        CompressedVSizeIndexedV3Writer writer = new CompressedVSizeIndexedV3Writer(offsetWriter, valueWriter);
        CompressedVSizeIndexedV3Supplier supplierFromIterable = CompressedVSizeIndexedV3Supplier.fromIterable(Iterables.transform(vals, new Function<int[], IndexedInts>() {

            @Nullable
            @Override
            public IndexedInts apply(@Nullable final int[] input) {
                return ArrayBasedIndexedInts.of(input);
            }
        }), offsetChunkFactor, maxValue, byteOrder, compressionStrategy);
        writer.open();
        for (int[] val : vals) {
            writer.add(val);
        }
        writer.close();
        long writtenLength = writer.getSerializedSize();
        final WritableByteChannel outputChannel = Channels.newChannel(ioPeon.makeOutputStream("output"));
        writer.writeToChannel(outputChannel, smoosher);
        outputChannel.close();
        smoosher.close();
        assertEquals(writtenLength, supplierFromIterable.getSerializedSize());
        // read from ByteBuffer and check values
        CompressedVSizeIndexedV3Supplier supplierFromByteBuffer = CompressedVSizeIndexedV3Supplier.fromByteBuffer(ByteBuffer.wrap(IOUtils.toByteArray(ioPeon.makeInputStream("output"))), byteOrder, null);
        indexedMultivalue = supplierFromByteBuffer.get();
        assertEquals(indexedMultivalue.size(), vals.size());
        for (int i = 0; i < vals.size(); ++i) {
            IndexedInts subVals = indexedMultivalue.get(i);
            assertEquals(subVals.size(), vals.get(i).length);
            for (int j = 0; j < subVals.size(); ++j) {
                assertEquals(subVals.get(j), vals.get(i)[j]);
            }
        }
        CloseQuietly.close(indexedMultivalue);
    } finally {
        ioPeon.close();
    }
}
Also used : WritableByteChannel(java.nio.channels.WritableByteChannel) Function(com.google.common.base.Function) FileSmoosher(io.druid.java.util.common.io.smoosh.FileSmoosher) CompressedVSizeIndexedV3Supplier(io.druid.segment.CompressedVSizeIndexedV3Supplier) Nullable(javax.annotation.Nullable)

Example 8 with FileSmoosher

use of io.druid.java.util.common.io.smoosh.FileSmoosher in project druid by druid-io.

the class CompressedVSizeIntsIndexedWriterTest method checkSerializedSizeAndData.

private void checkSerializedSizeAndData(int chunkSize) throws Exception {
    FileSmoosher smoosher = new FileSmoosher(FileUtils.getTempDirectory());
    CompressedVSizeIntsIndexedWriter writer = new CompressedVSizeIntsIndexedWriter(ioPeon, "test", vals.length > 0 ? Ints.max(vals) : 0, chunkSize, byteOrder, compressionStrategy);
    CompressedVSizeIntsIndexedSupplier supplierFromList = CompressedVSizeIntsIndexedSupplier.fromList(Ints.asList(vals), vals.length > 0 ? Ints.max(vals) : 0, chunkSize, byteOrder, compressionStrategy);
    writer.open();
    for (int val : vals) {
        writer.add(val);
    }
    writer.close();
    long writtenLength = writer.getSerializedSize();
    final WritableByteChannel outputChannel = Channels.newChannel(ioPeon.makeOutputStream("output"));
    writer.writeToChannel(outputChannel, smoosher);
    outputChannel.close();
    smoosher.close();
    assertEquals(writtenLength, supplierFromList.getSerializedSize());
    // read from ByteBuffer and check values
    CompressedVSizeIntsIndexedSupplier supplierFromByteBuffer = CompressedVSizeIntsIndexedSupplier.fromByteBuffer(ByteBuffer.wrap(IOUtils.toByteArray(ioPeon.makeInputStream("output"))), byteOrder, null);
    IndexedInts indexedInts = supplierFromByteBuffer.get();
    for (int i = 0; i < vals.length; ++i) {
        assertEquals(vals[i], indexedInts.get(i));
    }
    CloseQuietly.close(indexedInts);
}
Also used : FileSmoosher(io.druid.java.util.common.io.smoosh.FileSmoosher) WritableByteChannel(java.nio.channels.WritableByteChannel)

Aggregations

FileSmoosher (io.druid.java.util.common.io.smoosh.FileSmoosher)8 File (java.io.File)5 SmooshedFileMapper (io.druid.java.util.common.io.smoosh.SmooshedFileMapper)4 SmooshedWriter (io.druid.java.util.common.io.smoosh.SmooshedWriter)4 WritableByteChannel (java.nio.channels.WritableByteChannel)3 CompressedVSizeIndexedV3Supplier (io.druid.segment.CompressedVSizeIndexedV3Supplier)2 IOPeon (io.druid.segment.data.IOPeon)2 TmpFileIOPeon (io.druid.segment.data.TmpFileIOPeon)2 Function (com.google.common.base.Function)1 Closer (com.google.common.io.Closer)1 HyperLogLogCollector (io.druid.hll.HyperLogLogCollector)1 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)1 Column (io.druid.segment.column.Column)1 ColumnBuilder (io.druid.segment.column.ColumnBuilder)1 ColumnCapabilitiesImpl (io.druid.segment.column.ColumnCapabilitiesImpl)1 ColumnDescriptor (io.druid.segment.column.ColumnDescriptor)1 ComplexColumn (io.druid.segment.column.ComplexColumn)1 ValueType (io.druid.segment.column.ValueType)1 MMappedQueryableSegmentizerFactory (io.druid.segment.loading.MMappedQueryableSegmentizerFactory)1 FileOutputStream (java.io.FileOutputStream)1