kiszk commented on code in PR #48215:
URL: https://github.com/apache/arrow/pull/48215#discussion_r3425968191
##########
cpp/src/parquet/arrow/reader_internal.cc:
##########
@@ -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
+ 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) {
Review Comment:
Can we make it simpler w/o `memcpy()` like?
```
for (int64_t i = 0; i < n; ++i) {
// FromLittleEndian handles the load + byte-swap; .bits() gives the
// native-endian uint16 that Arrow's HalfFloatArray expects.
out16[i] =
::arrow::util::Float16::FromLittleEndian(fsb.GetValue(i)).bits();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]