|
19 | 19 | package org.apache.parquet.column.values.deltastrings; |
20 | 20 |
|
21 | 21 | import java.io.IOException; |
| 22 | +import java.nio.charset.StandardCharsets; |
22 | 23 | import org.apache.parquet.bytes.ByteBufferInputStream; |
23 | 24 | import org.apache.parquet.bytes.DirectByteBufferAllocator; |
24 | 25 | import org.apache.parquet.column.values.Utils; |
@@ -128,4 +129,24 @@ public void testWriterReset() throws Exception { |
128 | 129 |
|
129 | 130 | assertReadWrite(writer, new DeltaByteArrayReader(), values); |
130 | 131 | } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void testReusedBackingArrayRegression() throws Exception { |
| 135 | + DeltaByteArrayWriter writer = new DeltaByteArrayWriter(64 * 1024, 64 * 1024, new DirectByteBufferAllocator()); |
| 136 | + DeltaByteArrayReader reader = new DeltaByteArrayReader(); |
| 137 | + |
| 138 | + byte[] buffer = "parquet-000".getBytes(StandardCharsets.UTF_8); |
| 139 | + writer.writeBytes(Binary.fromReusedByteArray(buffer)); |
| 140 | + |
| 141 | + System.arraycopy("parquet-111".getBytes(StandardCharsets.UTF_8), 0, buffer, 0, buffer.length); |
| 142 | + writer.writeBytes(Binary.fromReusedByteArray(buffer)); |
| 143 | + |
| 144 | + System.arraycopy("parquet-222".getBytes(StandardCharsets.UTF_8), 0, buffer, 0, buffer.length); |
| 145 | + writer.writeBytes(Binary.fromReusedByteArray(buffer)); |
| 146 | + |
| 147 | + Binary[] decoded = Utils.readData(reader, writer.getBytes().toInputStream(), 3); |
| 148 | + Assert.assertEquals(Binary.fromString("parquet-000"), decoded[0]); |
| 149 | + Assert.assertEquals(Binary.fromString("parquet-111"), decoded[1]); |
| 150 | + Assert.assertEquals(Binary.fromString("parquet-222"), decoded[2]); |
| 151 | + } |
131 | 152 | } |
0 commit comments