quanghgx commented on code in PR #14232:
URL: https://github.com/apache/arrow/pull/14232#discussion_r1006039266
##########
cpp/src/arrow/compute/kernels/scalar_cast_test.cc:
##########
@@ -1910,6 +1919,30 @@ TEST(Cast, StringToFloating) {
}
}
+TEST(Cast, StringToDecimal) {
+ for (auto string_type : {utf8(), large_utf8()}) {
+ for (auto decimal_type : {decimal128(5, 2), decimal256(5, 2)}) {
+ auto strings =
+ ArrayFromJSON(string_type, R"(["0.01", null, "127.32", "200.43",
"0.54"])");
+ auto decimals =
+ ArrayFromJSON(decimal_type, R"(["0.01", null, "127.32", "200.43",
"0.54"])");
+ CheckCast(strings, decimals);
+
+ for (const auto& not_decimal : std::vector<std::string>{"z"}) {
+ auto options = CastOptions::Safe(decimal128(5, 2));
+ CheckCastFails(ArrayFromJSON(string_type, "[\"" + not_decimal +
"\"]"), options);
+ }
+
+#if !defined(_WIN32) || defined(NDEBUG)
Review Comment:
Sorry for bringing back this point, something feel not right so I checked a
bit more. Under the hood, StringToDecimal uses a custom parser:
[decimal.cc#L511](https://github.com/apache/arrow/blob/master/cpp/src/arrow/util/decimal.cc#L511)
->
[decimal.cc#L450](https://github.com/apache/arrow/blob/master/cpp/src/arrow/util/decimal.cc#L450)
->
[decimal.cc#L467](https://github.com/apache/arrow/blob/master/cpp/src/arrow/util/decimal.cc#L467)
It is independent of the std::locale. This test block (line 1936->1941) is
kind of redundant.
--
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]