| 416 | using CastListImpl = CastList<MapType, DestType>; |
| 417 | |
| 418 | static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) { |
| 419 | const CastOptions& options = CastState::Get(ctx); |
| 420 | |
| 421 | std::shared_ptr<DataType> entry_type = |
| 422 | checked_cast<const DestType&>(*out->type()).value_type(); |
| 423 | // Assert is struct with two fields |
| 424 | if (!(entry_type->id() == Type::STRUCT && entry_type->num_fields() == 2)) { |
| 425 | return Status::TypeError( |
| 426 | "Map type must be cast to a list<struct> with exactly two fields."); |
| 427 | } |
| 428 | std::shared_ptr<DataType> key_type = entry_type->field(0)->type(); |
| 429 | std::shared_ptr<DataType> value_type = entry_type->field(1)->type(); |
| 430 | |
| 431 | const ArraySpan& in_array = batch[0].array; |
| 432 | |
| 433 | ArrayData* out_array = out->array_data().get(); |
| 434 | out_array->buffers[0] = in_array.GetBuffer(0); |
| 435 | out_array->buffers[1] = in_array.GetBuffer(1); |
| 436 | |
| 437 | std::shared_ptr<ArrayData> entries = in_array.child_data[0].ToArrayData(); |
| 438 | |
| 439 | // Shift bitmap in case the source offset is non-zero |
| 440 | if (in_array.offset != 0 && in_array.buffers[0].data != nullptr) { |
| 441 | ARROW_ASSIGN_OR_RAISE(out_array->buffers[0], |
| 442 | CopyBitmap(ctx->memory_pool(), in_array.buffers[0].data, |
| 443 | in_array.offset, in_array.length)); |
| 444 | } |
| 445 | |
| 446 | RETURN_NOT_OK(CastListImpl::HandleOffsets(ctx, in_array, out_array, &entries)); |
| 447 | |
| 448 | // Handle keys |
| 449 | const std::shared_ptr<ArrayData>& keys = |
| 450 | entries->child_data[0]->Slice(entries->offset, entries->length); |
| 451 | ARROW_ASSIGN_OR_RAISE(Datum cast_keys, |
| 452 | Cast(keys, key_type, options, ctx->exec_context())); |
| 453 | DCHECK(cast_keys.is_array()); |
| 454 | |
| 455 | // Handle values |
| 456 | const std::shared_ptr<ArrayData>& values = |
| 457 | entries->child_data[1]->Slice(entries->offset, entries->length); |
| 458 | ARROW_ASSIGN_OR_RAISE(Datum cast_values, |
| 459 | Cast(values, value_type, options, ctx->exec_context())); |
| 460 | DCHECK(cast_values.is_array()); |
| 461 | |
| 462 | // Create struct array |
| 463 | std::shared_ptr<ArrayData> struct_array = |
| 464 | ArrayData::Make(entry_type, /*length=*/entries->length, {nullptr}, |
| 465 | {cast_keys.array(), cast_values.array()}, /*null_count=*/0); |
| 466 | out_array->child_data.push_back(struct_array); |
| 467 | |
| 468 | return Status::OK(); |
| 469 | } |
| 470 | }; |
| 471 | |
| 472 | template <typename DestType> |
nothing calls this directly
no test coverage detected