Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public String memUsageString(String prefix) {
@Override
public void writeBytes(Binary v) {
int i = 0;
byte[] vb = v.getBytes();
// copy() is a no-op for constant (non-reused) Binaries, and getBytesUnsafe()
// returns the backing array directly for ByteArrayBackedBinary — avoiding
// the unconditional array copy that getBytes() always performs.
byte[] vb = v.copy().getBytesUnsafe();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I address this area already in PR #3465. Can review it and reduce that one to the part which is not addressed there?

int length = previous.length < vb.length ? previous.length : vb.length;
// find the number of matching prefix bytes between this value and the previous one
for (i = 0; (i < length) && (previous[i] == vb[i]); i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.parquet.bytes.ByteBufferAllocator;
import org.apache.parquet.bytes.BytesInput;
import org.apache.parquet.bytes.CapacityByteArrayOutputStream;
import org.apache.parquet.bytes.LittleEndianDataOutputStream;
import org.apache.parquet.column.Encoding;
import org.apache.parquet.column.values.ValuesWriter;
import org.apache.parquet.io.ParquetEncodingException;
Expand All @@ -37,7 +36,6 @@ public class FixedLenByteArrayPlainValuesWriter extends ValuesWriter {
private static final Logger LOG = LoggerFactory.getLogger(PlainValuesWriter.class);

private CapacityByteArrayOutputStream arrayOut;
private LittleEndianDataOutputStream out;
private int length;
private ByteBufferAllocator allocator;

Expand All @@ -46,7 +44,6 @@ public FixedLenByteArrayPlainValuesWriter(
this.length = length;
this.allocator = allocator;
this.arrayOut = new CapacityByteArrayOutputStream(initialSize, pageSize, this.allocator);
this.out = new LittleEndianDataOutputStream(arrayOut);
}

@Override
Expand All @@ -56,7 +53,7 @@ public final void writeBytes(Binary v) {
"Fixed Binary size " + v.length() + " does not match field type length " + length);
}
try {
v.writeTo(out);
v.writeTo(arrayOut);
} catch (IOException e) {
throw new ParquetEncodingException("could not write fixed bytes", e);
}
Expand All @@ -69,11 +66,6 @@ public long getBufferedSize() {

@Override
public BytesInput getBytes() {
try {
out.flush();
} catch (IOException e) {
throw new ParquetEncodingException("could not write page", e);
}
LOG.debug("writing a buffer of size {}", arrayOut.size());
return BytesInput.from(arrayOut);
}
Expand Down