lidavidm commented on a change in pull request #12248:
URL: https://github.com/apache/arrow/pull/12248#discussion_r802209059



##########
File path: cpp/src/arrow/compute/kernels/scalar_cast_nested.cc
##########
@@ -150,6 +150,80 @@ void AddListCast(CastFunction* func) {
   DCHECK_OK(func->AddKernel(SrcType::type_id, std::move(kernel)));
 }
 
+struct CastStruct {
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    const CastOptions& options = CastState::Get(ctx);
+    const auto in_field_count =
+        checked_cast<const StructType&>(*batch[0].type()).num_fields();
+    const auto out_field_count =
+        checked_cast<const StructType&>(*out->type()).num_fields();
+
+    if (in_field_count != out_field_count) {
+      return Status::TypeError("struct field sizes do not match: ",
+                               batch[0].type()->ToString(), " ", 
out->type()->ToString());
+    }
+
+    for (int64_t i = 0; i < in_field_count; ++i) {
+      const auto in_field_name =
+          checked_cast<const StructType&>(*batch[0].type()).field(i)->name();
+      const auto out_field_name =
+          checked_cast<const StructType&>(*out->type()).field(i)->name();

Review comment:
       Again, would you mind elaborating?
   
   ```
     // OK to go from non-nullable to nullable...
     std::vector<std::shared_ptr<Field>> fields1 = {
         std::make_shared<Field>("a", int8(), false),
         std::make_shared<Field>("b", int8(), false)};
     std::shared_ptr<Array> a1, b1;
     a1 = ArrayFromJSON(int8(), "[1, 2]");
     b1 = ArrayFromJSON(int8(), "[3, 4]");
     ASSERT_OK_AND_ASSIGN(auto src1, StructArray::Make({a1, b1}, fields1));
   
     std::vector<std::shared_ptr<Field>> fields2 = {
         std::make_shared<Field>("a", int8(), true),
         std::make_shared<Field>("b", int8(), true)};
     std::shared_ptr<Array> a2, b2;
     a2 = ArrayFromJSON(int8(), "[1, null]");
     b2 = ArrayFromJSON(int8(), "[3, 4]");
     ASSERT_OK_AND_ASSIGN(auto dest1, StructArray::Make({a2, b2}, fields2));
   
     CheckCast(src1, dest1);
   ```
   
   I would expect the values not to change. I do not see why we are expecting a 
null value afterwards. We are casting `{a: int8() not null, b: int8() not 
null}` to {a: int8(), b: int8()}` and that should not change the _values_ at 
all.




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