zeroshade commented on code in PR #43957:
URL: https://github.com/apache/arrow/pull/43957#discussion_r1761353151
##########
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");
+
+ // First generate separate random values for individual components:
+ // boolean sign (including null-ness), and uint64 "digits" in big endian
order.
+ const auto& decimal_type = checked_cast<const DecimalType&>(*type_);
+
+ auto remaining_digits = decimal_type.precision();
Review Comment:
inherited from the original implementation for decimal128/256, i'll rename
the variable to `digits_to_generate`
--
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]