felipecrv commented on code in PR #48171:
URL: https://github.com/apache/arrow/pull/48171#discussion_r2566729261


##########
cpp/src/arrow/compute/kernels/scalar_cast_string.cc:
##########
@@ -304,8 +305,21 @@ BinaryToBinaryCastExec(KernelContext* ctx, const ExecSpan& 
batch, ExecResult* ou
     }
   }
 
-  // Start with a zero-copy cast, but change indices to expected size
-  RETURN_NOT_OK(ZeroCopyCastExec(ctx, batch, out));
+  std::shared_ptr<ArrayData> input_arr = input.ToArrayData();
+  ArrayData* output = out->array_data().get();
+  output->length = input_arr->length;
+  output->SetNullCount(input_arr->null_count);
+  output->buffers = std::move(input_arr->buffers);
+  output->child_data = std::move(input_arr->child_data);
+
+  if (output->buffers[0]) {
+    // If reusing the null bitmap, ensure offset into the first byte is the 
same as input.
+    output->offset = input_arr->offset % 8;
+    output->buffers[0] = SliceBuffer(output->buffers[0], input_arr->offset / 
8);
+  } else {
+    output->offset = 0;
+  }

Review Comment:
   But if you don't slice they get reallocated with the same length, no? 
Nevertheless, it becomes a creates a very weird relationship between this code 
and the function. Making it very non-obvious how it is correct.



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