Skip to content
Open
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
34 changes: 34 additions & 0 deletions cpp/src/parquet/arrow/reader_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,41 @@ Status TransferHalfFloat(RecordReader* reader, MemoryPool* pool,
std::shared_ptr<ChunkedArray> chunked_array;
RETURN_NOT_OK(
TransferBinary(reader, pool, field->WithType(binary_type), &chunked_array));
#if ARROW_LITTLE_ENDIAN
ARROW_ASSIGN_OR_RAISE(*out, chunked_array->View(field->type()));
#else
// Convert little-endian bytes from Parquet to native-endian HalfFloat
Copy link
Member

Choose a reason for hiding this comment

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

I would favor a different approach: turn TransferBinary into:

Status TransferBinary(RecordReader* reader, MemoryPool* pool,
                      const std::shared_ptr<Field>& logical_type_field,
                      std::function<Result<std::shared_ptr<Array>>(std::shared_ptr<Array>)> array_process,
                      std::shared_ptr<ChunkedArray>* out) {

such that the optional array_process is called for each chunk. If carefully coded, this will help limit memory consumption by disposing of old chunks while creating the new ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pitrou.. Thanks for your comments here.. Can I plan to implement this change in the next pass, since the present code change is working.. We want to enable the Apache/Arrow support on s390x as soon as possible since its blocking many of the OCP AI tests on IBM Z.. Thanks.. !!

std::vector<std::shared_ptr<::arrow::Array>> out_chunks;
out_chunks.reserve(chunked_array->num_chunks());

for (const auto& chunk : chunked_array->chunks()) {
auto fsb = std::static_pointer_cast<::arrow::FixedSizeBinaryArray>(chunk);
const int64_t n = fsb->length();

// Allocate buffer for native-endian uint16 values
ARROW_ASSIGN_OR_RAISE(auto data_buf,
::arrow::AllocateBuffer(n * sizeof(uint16_t), pool));
auto* out16 = reinterpret_cast<uint16_t*>(data_buf->mutable_data());

// Copy and convert from little-endian (Parquet spec) to native-endian
for (int64_t i = 0; i < n; ++i) {
uint16_t v;
std::memcpy(&v, fsb->GetValue(i), sizeof(uint16_t));
// Parquet spec: float16 stored as little-endian; convert to native
out16[i] = ::arrow::bit_util::FromLittleEndian(v);
}

// Create HalfFloatArray with the converted data
auto arr_data = ::arrow::ArrayData::Make(::arrow::float16(), n,
{fsb->null_bitmap(), std::move(data_buf)},
fsb->null_count());

out_chunks.push_back(::arrow::MakeArray(std::move(arr_data)));
}

*out =
std::make_shared<::arrow::ChunkedArray>(std::move(out_chunks), ::arrow::float16());
#endif
return Status::OK();
}

Expand Down
Loading