pitrou commented on code in PR #48205:
URL: https://github.com/apache/arrow/pull/48205#discussion_r2555481395
##########
cpp/src/parquet/column_writer.cc:
##########
@@ -2621,6 +2641,38 @@ struct SerializeFunctor<::parquet::FLBAType,
::arrow::HalfFloatType> {
return FLBA{reinterpret_cast<const uint8_t*>(value_ptr)};
}
};
+#else
+template <>
+struct SerializeFunctor<::parquet::FLBAType, ::arrow::HalfFloatType> {
+ Status Serialize(const ::arrow::HalfFloatArray& array, ArrowWriteContext*,
FLBA* out) {
+ const uint16_t* values = array.raw_values();
+ const int64_t length = array.length();
+
+ // Allocate buffer for little-endian converted values
+ converted_values_.resize(length);
+
+ if (array.null_count() == 0) {
+ for (int64_t i = 0; i < length; ++i) {
+ converted_values_[i] = ::arrow::bit_util::ToLittleEndian(values[i]);
+ out[i] = FLBA{reinterpret_cast<const uint8_t*>(&converted_values_[i])};
+ }
+ } else {
+ for (int64_t i = 0; i < length; ++i) {
+ if (array.IsValid(i)) {
+ converted_values_[i] = ::arrow::bit_util::ToLittleEndian(values[i]);
+ out[i] = FLBA{reinterpret_cast<const
uint8_t*>(&converted_values_[i])};
+ } else {
+ out[i] = FLBA{};
+ }
+ }
+ }
+ return Status::OK();
+ }
+
+ private:
+ std::vector<uint16_t> converted_values_;
+};
+#endif
Review Comment:
Please, reuse the `AllocateScratch` approach from the Decimal serializer.
You can introduce a mixin class if that makes things easier.
--
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]