cyb70289 commented on a change in pull request #11045:
URL: https://github.com/apache/arrow/pull/11045#discussion_r700938422
##########
File path: cpp/src/arrow/compute/kernels/scalar_cast_test.cc
##########
@@ -587,6 +589,36 @@ TEST(Cast, Decimal256ToInt) {
CheckCast(negative_scale, ArrayFromJSON(int64(), "[1234567890000,
-120000]"), options);
}
+TEST(Cast, IntegerToDecimal) {
+ for (auto decimal_type : {decimal128(21, 2), decimal256(21, 2)}) {
+ for (auto integer_type : kIntegerTypes) {
+ CheckCast(
+ ArrayFromJSON(integer_type, "[0, 7, null, 100, 99]"),
+ ArrayFromJSON(decimal_type, R"(["0.00", "7.00", null, "100.00",
"99.00"])"));
+ }
+ }
+
+ // extreme value
+ for (auto decimal_type : {decimal128(19, 0), decimal256(19, 0)}) {
+ CheckCast(ArrayFromJSON(int64(), "[-9223372036854775808,
9223372036854775807]"),
+ ArrayFromJSON(decimal_type,
+ R"(["-9223372036854775808",
"9223372036854775807"])"));
+ CheckCast(ArrayFromJSON(uint64(), "[0, 18446744073709551615]"),
+ ArrayFromJSON(decimal_type, R"(["0", "18446744073709551615"])"));
+ }
+
+ // insufficient output precision
+ {
+ CastOptions options;
+
+ options.to_type = decimal128(5, 3);
+ CheckCastFails(ArrayFromJSON(int8(), "[0]"), options);
+
+ options.to_type = decimal256(76, 67);
+ CheckCastFails(ArrayFromJSON(int32(), "[0]"), options);
+ }
Review comment:
Sure, will do.
--
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]