|
36 | 36 | import org.apache.iceberg.FileFormat; |
37 | 37 | import org.apache.iceberg.Metrics; |
38 | 38 | import org.apache.iceberg.PartitionSpec; |
| 39 | +import org.apache.iceberg.types.Conversions; |
| 40 | +import org.apache.iceberg.types.Types; |
39 | 41 | import org.junit.Test; |
40 | 42 |
|
41 | 43 | /** |
@@ -93,21 +95,18 @@ public void testFieldsInEqualsMethodInSyncWithGetterFields() { |
93 | 95 | */ |
94 | 96 | @Test |
95 | 97 | public void testBoundByteBufferIsCopiedByLimitNotBackingArrayLength() { |
96 | | - // Reproduce the shape iceberg-parquet produces in the wild: a ByteBuffer |
97 | | - // whose backing array is larger than [position, limit), with trailing |
98 | | - // 0x00 bytes. iceberg-parquet hits this because the JDK UTF-8 encoder |
99 | | - // over-allocates; here we build it explicitly so the test doesn't depend |
100 | | - // on encoder internals. |
| 98 | + // Encode bounds the same way iceberg-parquet does in the wild — via |
| 99 | + // Conversions.toByteBuffer(STRING, value). For UTF-8 strings of 10+ |
| 100 | + // characters the underlying JDK CharsetEncoder over-allocates by ~10% |
| 101 | + // and flips, producing a ByteBuffer with capacity > limit. |
101 | 102 | int columnId = 3; |
102 | | - byte[] expectedLower = "lower_bound_str".getBytes(StandardCharsets.UTF_8); |
103 | | - byte[] expectedUpper = "upper_bound_str".getBytes(StandardCharsets.UTF_8); |
| 103 | + String lowerValue = "lower_bound_str"; |
| 104 | + String upperValue = "upper_bound_str"; |
| 105 | + byte[] expectedLower = lowerValue.getBytes(StandardCharsets.UTF_8); |
| 106 | + byte[] expectedUpper = upperValue.getBytes(StandardCharsets.UTF_8); |
104 | 107 |
|
105 | | - ByteBuffer lower = ByteBuffer.allocate(expectedLower.length + 1); |
106 | | - lower.put(expectedLower); |
107 | | - lower.flip(); |
108 | | - ByteBuffer upper = ByteBuffer.allocate(expectedUpper.length + 1); |
109 | | - upper.put(expectedUpper); |
110 | | - upper.flip(); |
| 108 | + ByteBuffer lower = Conversions.toByteBuffer(Types.StringType.get(), lowerValue); |
| 109 | + ByteBuffer upper = Conversions.toByteBuffer(Types.StringType.get(), upperValue); |
111 | 110 |
|
112 | 111 | Map<Integer, ByteBuffer> lowerBounds = new HashMap<>(); |
113 | 112 | lowerBounds.put(columnId, lower); |
|
0 commit comments