Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
SPAKR-23972: Bulk write to ColumnVector when Parquet data is on the h…
…eap.
  • Loading branch information
rdblue committed May 7, 2018
commit 93b8ee876f6b9fef41b47fc7d8d4d5af0e8083e5
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.apache.parquet.column.values.ValuesReader;
import org.apache.parquet.io.api.Binary;
import org.apache.spark.unsafe.Platform;

/**
* An implementation of the Parquet PLAIN decoder that supports the vectorized interface.
Expand Down Expand Up @@ -71,8 +72,13 @@ public final void readIntegers(int total, WritableColumnVector c, int rowId) {
int requiredBytes = total * 4;
ByteBuffer buffer = getBuffer(requiredBytes);

for (int i = 0; i < total; i += 1) {
c.putInt(rowId + i, buffer.getInt());
if (buffer.hasArray()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we assert buffer.hasArray() is always true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, there is no guarantee that the buffer from Parquet is on the heap.

int offset = buffer.arrayOffset() + buffer.position();
c.putIntsLittleEndian(rowId, total, buffer.array(), offset - Platform.BYTE_ARRAY_OFFSET);
} else {
for (int i = 0; i < total; i += 1) {
c.putInt(rowId + i, buffer.getInt());
}
}
}

Expand All @@ -81,8 +87,13 @@ public final void readLongs(int total, WritableColumnVector c, int rowId) {
int requiredBytes = total * 8;
ByteBuffer buffer = getBuffer(requiredBytes);

for (int i = 0; i < total; i += 1) {
c.putLong(rowId + i, buffer.getLong());
if (buffer.hasArray()) {
int offset = buffer.arrayOffset() + buffer.position();
c.putLongsLittleEndian(rowId, total, buffer.array(), offset - Platform.BYTE_ARRAY_OFFSET);
} else {
for (int i = 0; i < total; i += 1) {
c.putLong(rowId + i, buffer.getLong());
}
}
}

Expand All @@ -91,8 +102,13 @@ public final void readFloats(int total, WritableColumnVector c, int rowId) {
int requiredBytes = total * 4;
ByteBuffer buffer = getBuffer(requiredBytes);

for (int i = 0; i < total; i += 1) {
c.putFloat(rowId + i, buffer.getFloat());
if (buffer.hasArray()) {
int offset = buffer.arrayOffset() + buffer.position();
c.putFloats(rowId, total, buffer.array(), offset - Platform.BYTE_ARRAY_OFFSET);
} else {
for (int i = 0; i < total; i += 1) {
c.putFloat(rowId + i, buffer.getFloat());
}
}
}

Expand All @@ -101,8 +117,13 @@ public final void readDoubles(int total, WritableColumnVector c, int rowId) {
int requiredBytes = total * 8;
ByteBuffer buffer = getBuffer(requiredBytes);

for (int i = 0; i < total; i += 1) {
c.putDouble(rowId + i, buffer.getDouble());
if (buffer.hasArray()) {
int offset = buffer.arrayOffset() + buffer.position();
c.putDoubles(rowId, total, buffer.array(), offset - Platform.BYTE_ARRAY_OFFSET);
} else {
for (int i = 0; i < total; i += 1) {
c.putDouble(rowId + i, buffer.getDouble());
}
}
}

Expand Down