zeroshade commented on code in PR #43957:
URL: https://github.com/apache/arrow/pull/43957#discussion_r1761349571


##########
cpp/src/arrow/testing/random.cc:
##########
@@ -343,8 +343,119 @@ struct DecimalGenerator {
   }
 };
 
+template <>
+struct DecimalGenerator<Decimal32Type> {
+  using DecimalBuilderType = typename TypeTraits<Decimal32Type>::BuilderType;
+  using DecimalValue = typename DecimalBuilderType::ValueType;
+
+  std::shared_ptr<DataType> type_;
+  RandomArrayGenerator* rng_;
+
+  static int32_t MaxDecimalInteger(int32_t digits) {
+    return static_cast<int32_t>(std::ceil(std::pow(10.0, digits))) - 1;
+  }
+
+  std::shared_ptr<Array> MakeRandomArray(int64_t size, double null_probability,
+                                         int64_t alignment, MemoryPool* 
memory_pool) {
+    static constexpr int32_t kMaxDigitsInInteger = 9;
+    static constexpr int kNumIntegers = Decimal32Type::kByteWidth / 4;
+    static_assert(
+        kNumIntegers == (Decimal32Type::kMaxPrecision + kMaxDigitsInInteger - 
1) /
+                            (kMaxDigitsInInteger + 1),
+        "inconsistent decimal metadata: kMaxPrecision doesn't match 
kByteWidth");

Review Comment:
   Isn't the purpose of this assert to validate that the precision *matches* 
`kByteWidth` as opposed to just verifying that the precision is equal to the 
max digits?



-- 
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]

Reply via email to