Search in sources :

Example 1 with OnHeapMemorySegmentWriteOutMedium

use of org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium in project druid by druid-io.

the class GenericIndexedWriterTest method writeLargeValueIntoLargeColumn.

@Test
public void writeLargeValueIntoLargeColumn() throws IOException {
    // Regression test for https://github.com/apache/druid/issues/9027.
    final GenericIndexedWriter<String> writer = new GenericIndexedWriter<>(new OnHeapMemorySegmentWriteOutMedium(), "test", GenericIndexed.STRING_STRATEGY, 100);
    writer.setIntMaxForCasting(150);
    writer.open();
    writer.write("i really like writing strings");
    writer.write("i really like writing strings");
    writer.write("i really like writing strings i really like writing strings i really like writing strings");
    writer.write("i really like writing strings");
    writer.writeTo(FileChannel.open(temporaryFolder.newFile().toPath(), StandardOpenOption.WRITE), new FileSmoosher(temporaryFolder.newFolder()));
}
Also used : FileSmoosher(org.apache.druid.java.util.common.io.smoosh.FileSmoosher) OnHeapMemorySegmentWriteOutMedium(org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium) Test(org.junit.Test)

Example 2 with OnHeapMemorySegmentWriteOutMedium

use of org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium in project druid by druid-io.

the class BaseColumnarLongsBenchmark method encodeToFile.

static int encodeToFile(long[] vals, String encoding, FileChannel output) throws IOException {
    SegmentWriteOutMedium writeOutMedium = new OnHeapMemorySegmentWriteOutMedium();
    ColumnarLongsSerializer serializer;
    switch(encoding) {
        case "lz4-longs":
            serializer = CompressionFactory.getLongSerializer(encoding, writeOutMedium, "lz4-longs", ByteOrder.LITTLE_ENDIAN, CompressionFactory.LongEncodingStrategy.LONGS, CompressionStrategy.LZ4);
            break;
        case "lz4-auto":
            serializer = CompressionFactory.getLongSerializer(encoding, writeOutMedium, "lz4-auto", ByteOrder.LITTLE_ENDIAN, CompressionFactory.LongEncodingStrategy.AUTO, CompressionStrategy.LZ4);
            break;
        case "none-longs":
            serializer = CompressionFactory.getLongSerializer(encoding, writeOutMedium, "none-longs", ByteOrder.LITTLE_ENDIAN, CompressionFactory.LongEncodingStrategy.LONGS, CompressionStrategy.NONE);
            break;
        case "none-auto":
            serializer = CompressionFactory.getLongSerializer(encoding, writeOutMedium, "none-auto", ByteOrder.LITTLE_ENDIAN, CompressionFactory.LongEncodingStrategy.AUTO, CompressionStrategy.NONE);
            break;
        default:
            throw new RuntimeException("unknown encoding");
    }
    serializer.open();
    for (long val : vals) {
        serializer.add(val);
    }
    serializer.writeTo(output, null);
    return (int) serializer.getSerializedSize();
}
Also used : OnHeapMemorySegmentWriteOutMedium(org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium) SegmentWriteOutMedium(org.apache.druid.segment.writeout.SegmentWriteOutMedium) ColumnarLongsSerializer(org.apache.druid.segment.data.ColumnarLongsSerializer) OnHeapMemorySegmentWriteOutMedium(org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium)

Example 3 with OnHeapMemorySegmentWriteOutMedium

use of org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium in project druid by druid-io.

the class GenericIndexedStringWriterTest method testRandomAccess.

@Test
public void testRandomAccess() throws IOException {
    OnHeapMemorySegmentWriteOutMedium segmentWriteOutMedium = new OnHeapMemorySegmentWriteOutMedium();
    GenericIndexedWriter<String> writer = new GenericIndexedWriter<>(segmentWriteOutMedium, "test", GenericIndexed.STRING_STRATEGY);
    writer.open();
    writer.write(null);
    List<String> strings = new ArrayList<>();
    strings.add(null);
    ThreadLocalRandom r = ThreadLocalRandom.current();
    for (int i = 0; i < 100_000; i++) {
        byte[] bs = new byte[r.nextInt(1, 10)];
        r.nextBytes(bs);
        String s = new String(bs, StandardCharsets.US_ASCII);
        strings.add(s);
        writer.write(s);
    }
    for (int i = 0; i < strings.size(); i++) {
        Assert.assertEquals(strings.get(i), writer.get(i));
    }
}
Also used : ArrayList(java.util.ArrayList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) OnHeapMemorySegmentWriteOutMedium(org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

OnHeapMemorySegmentWriteOutMedium (org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 FileSmoosher (org.apache.druid.java.util.common.io.smoosh.FileSmoosher)1 ColumnarLongsSerializer (org.apache.druid.segment.data.ColumnarLongsSerializer)1 SegmentWriteOutMedium (org.apache.druid.segment.writeout.SegmentWriteOutMedium)1 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)1