quanghgx commented on code in PR #14232:
URL: https://github.com/apache/arrow/pull/14232#discussion_r1004557575


##########
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:
   Hi @westonpace,
   You are right, I was kind of blindly copied over from 
[StringToFloating](https://github.com/apache/arrow/blob/master/cpp/src/arrow/compute/kernels/scalar_cast_test.cc#L1903)
 for LocaleGuard constructor.
    
   Looking back, it was started from: [ARROW-6108: [C++] Workaround Windows CRT 
crash on invalid 
locale](https://github.com/apache/arrow/commit/134e9cf3dc4b55dfd183b22b6f5176a95ba9e7c5)
   And, from my understanding, this to avoid changing std::locale to an invalid 
locale name, which might "hang" on a particular Windows C++ Runtime in debug 
build, as more detail in this related topic: 
https://gerrit.libreoffice.org/c/core/+/54110/
    
   In current arrow code base, there are instants of using this guard as in 
[value_parsing_test.cc#L149](https://github.com/apache/arrow/blob/master/cpp/src/arrow/util/value_parsing_test.cc#L149)
 beside 
[scalar_cast_test.cc](https://github.com/apache/arrow/blob/master/cpp/src/arrow/compute/kernels/scalar_cast_test.cc#L1903)
   



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