@@ -4119,7 +4119,7 @@ TEST(Cast, StructToDifferentNullabilityStruct) {
41194119 CheckCast (src_non_nullable, dest3_nullable);
41204120 }
41214121 {
4122- // But NOT OK to go from nullable to non-nullable...
4122+ // But when going from nullable to non-nullable, all data must be non-null ...
41234123 std::vector<std::shared_ptr<Field>> fields_src_nullable = {
41244124 std::make_shared<Field>(" a" , int8 (), true ),
41254125 std::make_shared<Field>(" b" , int8 (), true ),
@@ -4140,8 +4140,10 @@ TEST(Cast, StructToDifferentNullabilityStruct) {
41404140 const auto dest1_non_nullable = arrow::struct_ (fields_dest1_non_nullable);
41414141 const auto options1_non_nullable = CastOptions::Safe (dest1_non_nullable);
41424142 EXPECT_RAISES_WITH_MESSAGE_THAT (
4143- TypeError,
4144- ::testing::HasSubstr (" cannot cast nullable field to non-nullable field" ),
4143+ Invalid,
4144+ ::testing::HasSubstr (
4145+ " field 'a' of type int8 has nulls. Can't cast to non-nullable field 'a' "
4146+ " of type int64" ),
41454147 Cast(src_nullable, options1_non_nullable));
41464148
41474149 std::vector<std::shared_ptr<Field>> fields_dest2_non_nullable = {
@@ -4150,18 +4152,21 @@ TEST(Cast, StructToDifferentNullabilityStruct) {
41504152 const auto dest2_non_nullable = arrow::struct_ (fields_dest2_non_nullable);
41514153 const auto options2_non_nullable = CastOptions::Safe (dest2_non_nullable);
41524154 EXPECT_RAISES_WITH_MESSAGE_THAT (
4153- TypeError,
4154- ::testing::HasSubstr (" cannot cast nullable field to non-nullable field" ),
4155+ Invalid,
4156+ ::testing::HasSubstr (
4157+ " field 'a' of type int8 has nulls. Can't cast to non-nullable field 'a' "
4158+ " of type int64" ),
41554159 Cast(src_nullable, options2_non_nullable));
41564160
4157- std::vector<std::shared_ptr<Field>> fields_dest3_non_nullable = {
4161+ std::shared_ptr<Array> c_dest_no_nulls;
4162+ c_dest_no_nulls = ArrayFromJSON (int64 (), " [9, 11, 44]" );
4163+ std::vector<std::shared_ptr<Field>> fields_dest_no_nulls = {
41584164 std::make_shared<Field>(" c" , int64 (), false )};
4159- const auto dest3_non_nullable = arrow::struct_ (fields_dest3_non_nullable);
4160- const auto options3_non_nullable = CastOptions::Safe (dest3_non_nullable);
4161- EXPECT_RAISES_WITH_MESSAGE_THAT (
4162- TypeError,
4163- ::testing::HasSubstr (" cannot cast nullable field to non-nullable field" ),
4164- Cast(src_nullable, options3_non_nullable));
4165+ ASSERT_OK_AND_ASSIGN (auto dest_no_nulls,
4166+ StructArray::Make ({c_dest_no_nulls}, fields_dest_no_nulls));
4167+ const auto options3_non_nullable =
4168+ CastOptions::Safe (arrow::struct_ (fields_dest_no_nulls));
4169+ CheckCast (src_nullable, dest_no_nulls, options3_non_nullable);
41654170 }
41664171}
41674172
0 commit comments