@@ -851,7 +851,41 @@ Status TransferHalfFloat(RecordReader* reader, MemoryPool* pool,
851851 std::shared_ptr<ChunkedArray> chunked_array;
852852 RETURN_NOT_OK (
853853 TransferBinary (reader, pool, field->WithType (binary_type), &chunked_array));
854+ #if ARROW_LITTLE_ENDIAN
854855 ARROW_ASSIGN_OR_RAISE (*out, chunked_array->View (field->type ()));
856+ #else
857+ // Convert little-endian bytes from Parquet to native-endian HalfFloat
858+ std::vector<std::shared_ptr<::arrow::Array>> out_chunks;
859+ out_chunks.reserve (chunked_array->num_chunks ());
860+
861+ for (const auto & chunk : chunked_array->chunks ()) {
862+ auto fsb = std::static_pointer_cast<::arrow::FixedSizeBinaryArray>(chunk);
863+ const int64_t n = fsb->length ();
864+
865+ // Allocate buffer for native-endian uint16 values
866+ ARROW_ASSIGN_OR_RAISE (auto data_buf,
867+ ::arrow::AllocateBuffer (n * sizeof (uint16_t ), pool));
868+ auto * out16 = reinterpret_cast <uint16_t *>(data_buf->mutable_data ());
869+
870+ // Copy and convert from little-endian (Parquet spec) to native-endian
871+ for (int64_t i = 0 ; i < n; ++i) {
872+ uint16_t v;
873+ std::memcpy (&v, fsb->GetValue (i), sizeof (uint16_t ));
874+ // Parquet spec: float16 stored as little-endian; convert to native
875+ out16[i] = ::arrow::bit_util::FromLittleEndian (v);
876+ }
877+
878+ // Create HalfFloatArray with the converted data
879+ auto arr_data = ::arrow::ArrayData::Make (::arrow::float16 (), n,
880+ {fsb->null_bitmap (), std::move (data_buf)},
881+ fsb->null_count ());
882+
883+ out_chunks.push_back (::arrow::MakeArray (std::move (arr_data)));
884+ }
885+
886+ *out =
887+ std::make_shared<::arrow::ChunkedArray>(std::move (out_chunks), ::arrow::float16 ());
888+ #endif
855889 return Status::OK ();
856890}
857891
0 commit comments