NickCrews commented on code in PR #43782:
URL: https://github.com/apache/arrow/pull/43782#discussion_r1949503068
##########
cpp/src/arrow/compute/kernels/scalar_cast_nested.cc:
##########
@@ -403,17 +399,27 @@ struct CastStruct {
}
int out_field_index = 0;
- for (int field_index : fields_to_select) {
- const auto& target_type = out->type()->field(out_field_index++)->type();
- if (field_index == kFillNullSentinel) {
- ARROW_ASSIGN_OR_RAISE(auto nulls,
- MakeArrayOfNull(target_type->GetSharedPtr(),
batch.length));
+ for (int in_field_index : fields_to_select) {
+ const auto& in_field = in_type.field(in_field_index);
+ const auto& out_field = out_type.field(out_field_index++);
+ const auto& in_field_type = in_field->type();
+ const auto& out_field_type = out_field->type();
+ if (in_field_index == kFillNullSentinel) {
+ ARROW_ASSIGN_OR_RAISE(
+ auto nulls, MakeArrayOfNull(out_field_type->GetSharedPtr(),
batch.length));
out_array->child_data.push_back(nulls->data());
} else {
- const auto& values =
(in_array.child_data[field_index].ToArrayData()->Slice(
+ const auto& in_values =
(in_array.child_data[in_field_index].ToArrayData()->Slice(
in_array.offset, in_array.length));
- ARROW_ASSIGN_OR_RAISE(Datum cast_values,
- Cast(values, target_type, options,
ctx->exec_context()));
+ if (in_field->nullable() && !out_field->nullable() &&
+ in_values->GetNullCount() > 0) {
+ return Status::Invalid("field '", in_field->name(), "' of type ",
+ in_field_type->ToString(),
+ " has nulls. Can't cast to field '",
out_field->name(),
+ "' of non-nullable type ",
out_field_type->ToString());
Review Comment:
good catch, thank you! Fixed now.
--
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]