wjones127 commented on code in PR #14198:
URL: https://github.com/apache/arrow/pull/14198#discussion_r982812957


##########
cpp/src/arrow/compute/kernels/scalar_cast_nested.cc:
##########
@@ -206,6 +211,75 @@ void AddStructToStructCast(CastFunction* func) {
   DCHECK_OK(func->AddKernel(StructType::type_id, std::move(kernel)));
 }
 
+template <typename DestType>
+struct CastMap {
+  using CastListImpl = CastList<MapType, DestType>;
+
+  static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* 
out) {
+    const CastOptions& options = CastState::Get(ctx);
+
+    std::shared_ptr<DataType> entry_type =
+        checked_cast<const DestType&>(*out->type()).value_type();
+    // Assert is struct with two fields
+    if (!(entry_type->id() == Type::STRUCT && entry_type->num_fields() == 2)) {
+      return Status::TypeError(
+          "Map type must be cast to a list<struct> with exactly two fields.");
+    }
+    std::shared_ptr<DataType> key_type = entry_type->field(0)->type();
+    std::shared_ptr<DataType> value_type = entry_type->field(1)->type();
+
+    const ArraySpan& in_array = batch[0].array;
+
+    ArrayData* out_array = out->array_data().get();
+    out_array->buffers[0] = in_array.GetBuffer(0);
+    out_array->buffers[1] = in_array.GetBuffer(1);
+
+    std::shared_ptr<ArrayData> entries = in_array.child_data[0].ToArrayData();
+
+    RETURN_NOT_OK(CastListImpl::HandleOffsets(ctx, in_array, out_array, 
&entries));
+
+    // Handle keys
+    const std::shared_ptr<ArrayData>& keys =
+        entries->child_data[0]->Slice(entries->offset, entries->length);
+    ARROW_ASSIGN_OR_RAISE(Datum cast_keys,
+                          Cast(keys, key_type, options, ctx->exec_context()));
+    DCHECK(cast_keys.is_array());
+
+    // Handle values
+    const std::shared_ptr<ArrayData>& values =
+        entries->child_data[1]->Slice(entries->offset, entries->length);
+    ARROW_ASSIGN_OR_RAISE(Datum cast_values,
+                          Cast(values, value_type, options, 
ctx->exec_context()));
+    DCHECK(cast_values.is_array());
+
+    // Copy null bitmap
+    std::shared_ptr<Buffer> null_bitmap;
+    if (in_array.buffers[0].data != nullptr) {

Review Comment:
   Whoops this part is dead code. I had the validity bitmap handling in 
`HandleOffsets()`, but that's a little confusing, so I'll put it out of there.



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