Search in sources :

Example 1 with DeltaByteArrayWriter

use of org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter in project parquet-mr by apache.

the class BenchmarkDeltaByteArray method benchmarkRandomStringsWithDeltaLengthByteArrayValuesWriter.

@BenchmarkOptions(benchmarkRounds = 20, warmupRounds = 4)
@Test
public void benchmarkRandomStringsWithDeltaLengthByteArrayValuesWriter() throws IOException {
    DeltaByteArrayWriter writer = new DeltaByteArrayWriter(64 * 1024, 64 * 1024, new DirectByteBufferAllocator());
    DeltaByteArrayReader reader = new DeltaByteArrayReader();
    Utils.writeData(writer, values);
    ByteBufferInputStream data = writer.getBytes().toInputStream();
    Binary[] bin = Utils.readData(reader, data, values.length);
    System.out.println("size " + data.position());
}
Also used : DirectByteBufferAllocator(org.apache.parquet.bytes.DirectByteBufferAllocator) DeltaByteArrayWriter(org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter) ByteBufferInputStream(org.apache.parquet.bytes.ByteBufferInputStream) DeltaByteArrayReader(org.apache.parquet.column.values.deltastrings.DeltaByteArrayReader) Binary(org.apache.parquet.io.api.Binary) Test(org.junit.Test) BenchmarkOptions(com.carrotsearch.junitbenchmarks.BenchmarkOptions)

Example 2 with DeltaByteArrayWriter

use of org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter in project parquet-mr by apache.

the class TestCorruptDeltaByteArrays method testOldReassemblyWithoutCorruption.

@Test
public void testOldReassemblyWithoutCorruption() throws Exception {
    DeltaByteArrayWriter writer = getDeltaByteArrayWriter();
    for (int i = 0; i < 10; i += 1) {
        writer.writeBytes(Binary.fromString(str(i)));
    }
    ByteBuffer firstPageBytes = writer.getBytes().toByteBuffer();
    // sets previous to new byte[0]
    writer.reset();
    for (int i = 10; i < 20; i += 1) {
        writer.writeBytes(Binary.fromString(str(i)));
    }
    ByteBuffer secondPageBytes = writer.getBytes().toByteBuffer();
    DeltaByteArrayReader firstPageReader = new DeltaByteArrayReader();
    firstPageReader.initFromPage(10, ByteBufferInputStream.wrap(firstPageBytes));
    for (int i = 0; i < 10; i += 1) {
        assertEquals(firstPageReader.readBytes().toStringUsingUTF8(), str(i));
    }
    DeltaByteArrayReader secondPageReader = new DeltaByteArrayReader();
    secondPageReader.initFromPage(10, ByteBufferInputStream.wrap(secondPageBytes));
    for (int i = 10; i < 20; i += 1) {
        assertEquals(secondPageReader.readBytes().toStringUsingUTF8(), str(i));
    }
}
Also used : DeltaByteArrayWriter(org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter) DeltaByteArrayReader(org.apache.parquet.column.values.deltastrings.DeltaByteArrayReader) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with DeltaByteArrayWriter

use of org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter in project parquet-mr by apache.

the class TestCorruptDeltaByteArrays method testColumnReaderImplWithCorruptPage.

@Test
public void testColumnReaderImplWithCorruptPage() throws Exception {
    ColumnDescriptor column = new ColumnDescriptor(new String[] { "s" }, PrimitiveType.PrimitiveTypeName.BINARY, 0, 0);
    MemPageStore pages = new MemPageStore(0);
    PageWriter memWriter = pages.getPageWriter(column);
    ParquetProperties parquetProps = ParquetProperties.builder().withDictionaryEncoding(false).build();
    // get generic repetition and definition level bytes to use for pages
    ValuesWriter rdValues = parquetProps.newDefinitionLevelWriter(column);
    for (int i = 0; i < 10; i += 1) {
        rdValues.writeInteger(0);
    }
    // use a byte array backed BytesInput because it is reused
    BytesInput rd = BytesInput.from(rdValues.getBytes().toByteArray());
    DeltaByteArrayWriter writer = getDeltaByteArrayWriter();
    String lastValue = null;
    List<String> values = new ArrayList<String>();
    for (int i = 0; i < 10; i += 1) {
        lastValue = str(i);
        writer.writeBytes(Binary.fromString(lastValue));
        values.add(lastValue);
    }
    memWriter.writePage(BytesInput.concat(rd, rd, writer.getBytes()), 10, /* number of values in the page */
    new BinaryStatistics(), rdValues.getEncoding(), rdValues.getEncoding(), writer.getEncoding());
    pages.addRowCount(10);
    // sets previous to new byte[0]
    writer.reset();
    corruptWriter(writer, lastValue);
    for (int i = 10; i < 20; i += 1) {
        String value = str(i);
        writer.writeBytes(Binary.fromString(value));
        values.add(value);
    }
    memWriter.writePage(BytesInput.concat(rd, rd, writer.getBytes()), 10, /* number of values in the page */
    new BinaryStatistics(), rdValues.getEncoding(), rdValues.getEncoding(), writer.getEncoding());
    pages.addRowCount(10);
    final List<String> actualValues = new ArrayList<String>();
    PrimitiveConverter converter = new PrimitiveConverter() {

        @Override
        public void addBinary(Binary value) {
            actualValues.add(value.toStringUsingUTF8());
        }
    };
    ColumnReaderImpl columnReader = new ColumnReaderImpl(column, pages.getPageReader(column), converter, new ParsedVersion("parquet-mr", "1.6.0", "abcd"));
    while (actualValues.size() < columnReader.getTotalValueCount()) {
        columnReader.writeCurrentValueToConverter();
        columnReader.consume();
    }
    Assert.assertEquals(values, actualValues);
}
Also used : BytesInput(org.apache.parquet.bytes.BytesInput) DeltaByteArrayWriter(org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter) ColumnDescriptor(org.apache.parquet.column.ColumnDescriptor) ArrayList(java.util.ArrayList) ParquetProperties(org.apache.parquet.column.ParquetProperties) BinaryStatistics(org.apache.parquet.column.statistics.BinaryStatistics) PrimitiveConverter(org.apache.parquet.io.api.PrimitiveConverter) MemPageStore(org.apache.parquet.column.page.mem.MemPageStore) Binary(org.apache.parquet.io.api.Binary) ValuesWriter(org.apache.parquet.column.values.ValuesWriter) ParsedVersion(org.apache.parquet.VersionParser.ParsedVersion) PageWriter(org.apache.parquet.column.page.PageWriter) Test(org.junit.Test)

Example 4 with DeltaByteArrayWriter

use of org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter in project parquet-mr by apache.

the class TestCorruptDeltaByteArrays method testReassemblyWithoutCorruption.

@Test
public void testReassemblyWithoutCorruption() throws Exception {
    DeltaByteArrayWriter writer = getDeltaByteArrayWriter();
    for (int i = 0; i < 10; i += 1) {
        writer.writeBytes(Binary.fromString(str(i)));
    }
    ByteBuffer firstPageBytes = writer.getBytes().toByteBuffer();
    // sets previous to new byte[0]
    writer.reset();
    for (int i = 10; i < 20; i += 1) {
        writer.writeBytes(Binary.fromString(str(i)));
    }
    ByteBuffer secondPageBytes = writer.getBytes().toByteBuffer();
    DeltaByteArrayReader firstPageReader = new DeltaByteArrayReader();
    firstPageReader.initFromPage(10, ByteBufferInputStream.wrap(firstPageBytes));
    for (int i = 0; i < 10; i += 1) {
        assertEquals(firstPageReader.readBytes().toStringUsingUTF8(), str(i));
    }
    DeltaByteArrayReader secondPageReader = new DeltaByteArrayReader();
    secondPageReader.initFromPage(10, ByteBufferInputStream.wrap(secondPageBytes));
    secondPageReader.setPreviousReader(firstPageReader);
    for (int i = 10; i < 20; i += 1) {
        assertEquals(secondPageReader.readBytes().toStringUsingUTF8(), str(i));
    }
}
Also used : DeltaByteArrayWriter(org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter) DeltaByteArrayReader(org.apache.parquet.column.values.deltastrings.DeltaByteArrayReader) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with DeltaByteArrayWriter

use of org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter in project parquet-mr by apache.

the class TestCorruptDeltaByteArrays method testReassemblyWithCorruptPage.

@Test
public void testReassemblyWithCorruptPage() throws Exception {
    DeltaByteArrayWriter writer = getDeltaByteArrayWriter();
    String lastValue = null;
    for (int i = 0; i < 10; i += 1) {
        lastValue = str(i);
        writer.writeBytes(Binary.fromString(lastValue));
    }
    ByteBuffer firstPageBytes = writer.getBytes().toByteBuffer();
    // sets previous to new byte[0]
    writer.reset();
    corruptWriter(writer, lastValue);
    for (int i = 10; i < 20; i += 1) {
        writer.writeBytes(Binary.fromString(str(i)));
    }
    ByteBuffer corruptPageBytes = writer.getBytes().toByteBuffer();
    DeltaByteArrayReader firstPageReader = new DeltaByteArrayReader();
    firstPageReader.initFromPage(10, ByteBufferInputStream.wrap(firstPageBytes));
    for (int i = 0; i < 10; i += 1) {
        assertEquals(str(i), firstPageReader.readBytes().toStringUsingUTF8());
    }
    DeltaByteArrayReader corruptPageReader = new DeltaByteArrayReader();
    corruptPageReader.initFromPage(10, ByteBufferInputStream.wrap(corruptPageBytes));
    try {
        corruptPageReader.readBytes();
        fail("Corrupt page did not throw an exception when read");
    } catch (ArrayIndexOutOfBoundsException e) {
    // expected, this is a corrupt page
    }
    DeltaByteArrayReader secondPageReader = new DeltaByteArrayReader();
    secondPageReader.initFromPage(10, ByteBufferInputStream.wrap(corruptPageBytes));
    secondPageReader.setPreviousReader(firstPageReader);
    for (int i = 10; i < 20; i += 1) {
        assertEquals(secondPageReader.readBytes().toStringUsingUTF8(), str(i));
    }
}
Also used : DeltaByteArrayWriter(org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter) DeltaByteArrayReader(org.apache.parquet.column.values.deltastrings.DeltaByteArrayReader) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

DeltaByteArrayWriter (org.apache.parquet.column.values.deltastrings.DeltaByteArrayWriter)6 Test (org.junit.Test)6 DeltaByteArrayReader (org.apache.parquet.column.values.deltastrings.DeltaByteArrayReader)5 ByteBuffer (java.nio.ByteBuffer)3 Binary (org.apache.parquet.io.api.Binary)3 BenchmarkOptions (com.carrotsearch.junitbenchmarks.BenchmarkOptions)2 ByteBufferInputStream (org.apache.parquet.bytes.ByteBufferInputStream)2 DirectByteBufferAllocator (org.apache.parquet.bytes.DirectByteBufferAllocator)2 ArrayList (java.util.ArrayList)1 ParsedVersion (org.apache.parquet.VersionParser.ParsedVersion)1 BytesInput (org.apache.parquet.bytes.BytesInput)1 ColumnDescriptor (org.apache.parquet.column.ColumnDescriptor)1 ParquetProperties (org.apache.parquet.column.ParquetProperties)1 PageWriter (org.apache.parquet.column.page.PageWriter)1 MemPageStore (org.apache.parquet.column.page.mem.MemPageStore)1 BinaryStatistics (org.apache.parquet.column.statistics.BinaryStatistics)1 ValuesWriter (org.apache.parquet.column.values.ValuesWriter)1 PrimitiveConverter (org.apache.parquet.io.api.PrimitiveConverter)1