pitrou commented on code in PR #43782:
URL: https://github.com/apache/arrow/pull/43782#discussion_r1944374517


##########
cpp/src/arrow/compute/kernels/scalar_cast_test.cc:
##########
@@ -2964,28 +2964,31 @@ TEST(Cast, StructToDifferentNullabilityStruct) {
     const auto dest1_non_nullable = arrow::struct_(fields_dest1_non_nullable);
     const auto options1_non_nullable = CastOptions::Safe(dest1_non_nullable);
     EXPECT_RAISES_WITH_MESSAGE_THAT(
-        TypeError,
-        ::testing::HasSubstr("cannot cast nullable field to non-nullable 
field"),
+        Invalid,
+        ::testing::HasSubstr(
+            "field 'a' has nulls. Can't cast to non-nullable type int64"),
         Cast(src_nullable, options1_non_nullable));
 
     std::vector<std::shared_ptr<Field>> fields_dest2_non_nullable = {
         std::make_shared<Field>("a", int64(), false),
         std::make_shared<Field>("c", int64(), false)};
     const auto dest2_non_nullable = arrow::struct_(fields_dest2_non_nullable);
-    const auto options2_non_nullable = CastOptions::Safe(dest2_non_nullable);
+    const auto options2_non_nullable = CastOptions::Unsafe(dest2_non_nullable);
     EXPECT_RAISES_WITH_MESSAGE_THAT(
-        TypeError,
-        ::testing::HasSubstr("cannot cast nullable field to non-nullable 
field"),
+        Invalid,
+        ::testing::HasSubstr(
+            "field 'a' has nulls. Can't cast to non-nullable type int64"),
         Cast(src_nullable, options2_non_nullable));
 
-    std::vector<std::shared_ptr<Field>> fields_dest3_non_nullable = {
+    std::shared_ptr<Array> c_dest_no_nulls;
+    c_dest_no_nulls = ArrayFromJSON(int64(), "[9, 11, 44]");
+    std::vector<std::shared_ptr<Field>> fields_dest_no_nulls = {
         std::make_shared<Field>("c", int64(), false)};
-    const auto dest3_non_nullable = arrow::struct_(fields_dest3_non_nullable);
-    const auto options3_non_nullable = CastOptions::Safe(dest3_non_nullable);
-    EXPECT_RAISES_WITH_MESSAGE_THAT(
-        TypeError,
-        ::testing::HasSubstr("cannot cast nullable field to non-nullable 
field"),
-        Cast(src_nullable, options3_non_nullable));
+    ASSERT_OK_AND_ASSIGN(auto dest_no_nulls,
+                         StructArray::Make({c_dest_no_nulls}, 
fields_dest_no_nulls));
+    const auto options3_non_nullable =
+        CastOptions::Unsafe(arrow::struct_(fields_dest_no_nulls));

Review Comment:
   Similarly, why `Unsafe`?



##########
cpp/src/arrow/compute/kernels/scalar_cast_test.cc:
##########
@@ -2964,28 +2964,31 @@ TEST(Cast, StructToDifferentNullabilityStruct) {
     const auto dest1_non_nullable = arrow::struct_(fields_dest1_non_nullable);
     const auto options1_non_nullable = CastOptions::Safe(dest1_non_nullable);
     EXPECT_RAISES_WITH_MESSAGE_THAT(
-        TypeError,
-        ::testing::HasSubstr("cannot cast nullable field to non-nullable 
field"),
+        Invalid,
+        ::testing::HasSubstr(
+            "field 'a' has nulls. Can't cast to non-nullable type int64"),
         Cast(src_nullable, options1_non_nullable));
 
     std::vector<std::shared_ptr<Field>> fields_dest2_non_nullable = {
         std::make_shared<Field>("a", int64(), false),
         std::make_shared<Field>("c", int64(), false)};
     const auto dest2_non_nullable = arrow::struct_(fields_dest2_non_nullable);
-    const auto options2_non_nullable = CastOptions::Safe(dest2_non_nullable);
+    const auto options2_non_nullable = CastOptions::Unsafe(dest2_non_nullable);

Review Comment:
   Why do we need to switch from `Safe` to `Unsafe` here?



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to