This is an automated email from the ASF dual-hosted git repository.
zanmato1984 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new fea7421c13 GH-48740: [C++] Add missing CTypeTraits for decimal types
(#50153)
fea7421c13 is described below
commit fea7421c138f76b1d559c962d321276ed6b2300b
Author: Naurder <[email protected]>
AuthorDate: Fri Aug 21 22:31:27 2026 +0200
GH-48740: [C++] Add missing CTypeTraits for decimal types (#50153)
### Rationale for this change
As reported in #48740, the `CTypeTraits` specializations were missing for
decimal types. This prevented generic code from correctly mapping C++ decimal
types to Arrow types.
### What changes are included in this PR?
* Added `CTypeTraits<Decimal128>` mapping to `Decimal128Type`.
* Added `CTypeTraits<Decimal256>` mapping to `Decimal256Type`.
### Are these changes tested?
Yes, via existing type traits tests in the CI pipeline.
### Are there any user-facing changes?
No.
Closes #48740
* GitHub Issue: #48740
Lead-authored-by: Naurder <[email protected]>
Co-authored-by: Rossi Sun <[email protected]>
Signed-off-by: Rossi Sun <[email protected]>
---
cpp/src/arrow/type_test.cc | 14 ++++++++++++++
cpp/src/arrow/type_traits.h | 20 ++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/cpp/src/arrow/type_test.cc b/cpp/src/arrow/type_test.cc
index 6197ad58eb..133afbfa0c 100644
--- a/cpp/src/arrow/type_test.cc
+++ b/cpp/src/arrow/type_test.cc
@@ -1493,6 +1493,20 @@ PRIMITIVE_TEST(DoubleType, double, DOUBLE, "double");
PRIMITIVE_TEST(BooleanType, bool, BOOL, "bool");
+TEST(TypesTest, DecimalTraits) {
+ static_assert(std::is_same_v<TypeTraits<Decimal32Type>::CType, Decimal32>);
+ static_assert(std::is_same_v<CTypeTraits<Decimal32>::ArrowType,
Decimal32Type>);
+
+ static_assert(std::is_same_v<TypeTraits<Decimal64Type>::CType, Decimal64>);
+ static_assert(std::is_same_v<CTypeTraits<Decimal64>::ArrowType,
Decimal64Type>);
+
+ static_assert(std::is_same_v<TypeTraits<Decimal128Type>::CType, Decimal128>);
+ static_assert(std::is_same_v<CTypeTraits<Decimal128>::ArrowType,
Decimal128Type>);
+
+ static_assert(std::is_same_v<TypeTraits<Decimal256Type>::CType, Decimal256>);
+ static_assert(std::is_same_v<CTypeTraits<Decimal256>::ArrowType,
Decimal256Type>);
+}
+
TEST(TestBinaryType, ToString) {
BinaryType t1;
BinaryType e1;
diff --git a/cpp/src/arrow/type_traits.h b/cpp/src/arrow/type_traits.h
index 1b7a02e108..fda3e3be12 100644
--- a/cpp/src/arrow/type_traits.h
+++ b/cpp/src/arrow/type_traits.h
@@ -357,6 +357,26 @@ struct TypeTraits<Decimal256Type> {
constexpr static bool is_parameter_free = false;
};
+template <>
+struct CTypeTraits<Decimal32> : public TypeTraits<Decimal32Type> {
+ using ArrowType = Decimal32Type;
+};
+
+template <>
+struct CTypeTraits<Decimal64> : public TypeTraits<Decimal64Type> {
+ using ArrowType = Decimal64Type;
+};
+
+template <>
+struct CTypeTraits<Decimal128> : public TypeTraits<Decimal128Type> {
+ using ArrowType = Decimal128Type;
+};
+
+template <>
+struct CTypeTraits<Decimal256> : public TypeTraits<Decimal256Type> {
+ using ArrowType = Decimal256Type;
+};
+
template <>
struct TypeTraits<BinaryType> {
using ArrayType = BinaryArray;