diff --git a/lib/trino-parquet/src/main/java/io/trino/parquet/writer/valuewriter/BinaryValueWriter.java b/lib/trino-parquet/src/main/java/io/trino/parquet/writer/valuewriter/BinaryValueWriter.java index 7a7cefac7cca..940be4d18a6b 100644 --- a/lib/trino-parquet/src/main/java/io/trino/parquet/writer/valuewriter/BinaryValueWriter.java +++ b/lib/trino-parquet/src/main/java/io/trino/parquet/writer/valuewriter/BinaryValueWriter.java @@ -41,7 +41,9 @@ public void write(Block block) for (int i = 0; i < block.getPositionCount(); i++) { if (!block.isNull(i)) { Slice slice = type.getSlice(block, i); - Binary binary = Binary.fromConstantByteBuffer(slice.toByteBuffer()); + // fromReusedByteBuffer must be used instead of fromConstantByteBuffer to avoid retaining entire + // base byte array of the Slice in DictionaryValuesWriter.PlainBinaryDictionaryValuesWriter + Binary binary = Binary.fromReusedByteBuffer(slice.toByteBuffer()); valuesWriter.writeBytes(binary); getStatistics().updateStats(binary); }