@@ -149,6 +149,8 @@ struct GetViewType<Decimal128Type> {
149149 static T LogicalValue (PhysicalType value) {
150150 return Decimal128 (reinterpret_cast <const uint8_t *>(value.data ()));
151151 }
152+
153+ static T LogicalValue (T value) { return value; }
152154};
153155
154156template <>
@@ -159,6 +161,8 @@ struct GetViewType<Decimal256Type> {
159161 static T LogicalValue (PhysicalType value) {
160162 return Decimal256 (reinterpret_cast <const uint8_t *>(value.data ()));
161163 }
164+
165+ static T LogicalValue (T value) { return value; }
162166};
163167
164168template <typename Type, typename Enable = void >
@@ -243,6 +247,18 @@ struct ArrayIterator<Type, enable_if_base_binary<Type>> {
243247 }
244248};
245249
250+ template <typename Type>
251+ struct ArrayIterator <Type, enable_if_decimal<Type>> {
252+ using T = typename TypeTraits<Type>::ScalarType::ValueType;
253+ using endian_agnostic = std::array<uint8_t , sizeof (T)>;
254+ const endian_agnostic* values;
255+
256+ explicit ArrayIterator (const ArrayData& data)
257+ : values(data.GetValues<endian_agnostic>(1 )) {}
258+
259+ T operator ()() { return T{values++->data ()}; }
260+ };
261+
246262// Iterator over various output array types, taking a GetOutputType<Type>
247263
248264template <typename Type, typename Enable = void >
@@ -262,6 +278,20 @@ struct OutputArrayWriter<Type, enable_if_has_c_type_not_boolean<Type>> {
262278 void WriteNull () { *values++ = T{}; }
263279};
264280
281+ template <typename Type>
282+ struct OutputArrayWriter <Type, enable_if_decimal<Type>> {
283+ using T = typename TypeTraits<Type>::ScalarType::ValueType;
284+ using endian_agnostic = std::array<uint8_t , sizeof (T)>;
285+ endian_agnostic* values;
286+
287+ explicit OutputArrayWriter (ArrayData* data)
288+ : values(data->GetMutableValues<endian_agnostic>(1 )) {}
289+
290+ void Write (T value) { value.ToBytes (values++->data ()); }
291+
292+ void WriteNull () { T{}.ToBytes (values++->data ()); }
293+ };
294+
265295// (Un)box Scalar to / from C++ value
266296
267297template <typename Type, typename Enable = void >
@@ -538,6 +568,22 @@ struct OutputAdapter<Type, enable_if_base_binary<Type>> {
538568 }
539569};
540570
571+ template <typename Type>
572+ struct OutputAdapter <Type, enable_if_decimal<Type>> {
573+ using T = typename TypeTraits<Type>::ScalarType::ValueType;
574+ using endian_agnostic = std::array<uint8_t , sizeof (T)>;
575+
576+ template <typename Generator>
577+ static Status Write (KernelContext*, Datum* out, Generator&& generator) {
578+ ArrayData* out_arr = out->mutable_array ();
579+ auto out_data = out_arr->GetMutableValues <endian_agnostic>(1 );
580+ for (int64_t i = 0 ; i < out_arr->length ; ++i) {
581+ generator ().ToBytes (out_data++->data ());
582+ }
583+ return Status::OK ();
584+ }
585+ };
586+
541587// A kernel exec generator for unary functions that addresses both array and
542588// scalar inputs and dispatches input iteration and output writing to other
543589// templates
0 commit comments