| 444 | // length |
| 445 | template <typename Type> |
| 446 | Status StringDataTransform(KernelContext* ctx, const ExecSpan& batch, |
| 447 | TransformFunc transform, ExecResult* out) { |
| 448 | using offset_type = typename Type::offset_type; |
| 449 | |
| 450 | const ArraySpan& input = batch[0].array; |
| 451 | ArrayData* out_arr = out->array_data().get(); |
| 452 | |
| 453 | const auto offsets = input.GetValues<offset_type>(1); |
| 454 | int64_t offset_nbytes = (input.length + 1) * sizeof(offset_type); |
| 455 | if (input.offset == 0) { |
| 456 | // We can reuse offsets from input if the input owns it |
| 457 | if (input.buffers[1].owner != nullptr) { |
| 458 | out_arr->buffers[1] = input.GetBuffer(1); |
| 459 | } else { |
| 460 | RETURN_NOT_OK(ctx->Allocate(offset_nbytes).Value(&out_arr->buffers[1])); |
| 461 | std::memcpy(out_arr->buffers[1]->mutable_data(), input.buffers[1].data, |
| 462 | offset_nbytes); |
| 463 | } |
| 464 | } else { |
| 465 | // We must allocate new space for the offsets and shift the existing offsets |
| 466 | RETURN_NOT_OK(ctx->Allocate(offset_nbytes).Value(&out_arr->buffers[1])); |
| 467 | auto out_offsets = |
| 468 | reinterpret_cast<offset_type*>(out_arr->buffers[1]->mutable_data()); |
| 469 | offset_type first_offset = offsets[0]; |
| 470 | for (int64_t i = 0; i < input.length; ++i) { |
| 471 | *out_offsets++ = offsets[i] - first_offset; |
| 472 | } |
| 473 | *out_offsets = offsets[input.length] - first_offset; |
| 474 | } |
| 475 | |
| 476 | int64_t data_nbytes = GetVarBinaryValuesLength<offset_type>(input); |
| 477 | if (input.length > 0) { |
| 478 | // Allocate space for output data |
| 479 | if (data_nbytes > 0) { |
| 480 | RETURN_NOT_OK(ctx->Allocate(data_nbytes).Value(&out_arr->buffers[2])); |
| 481 | transform(input.buffers[2].data + offsets[0], data_nbytes, |
| 482 | out_arr->buffers[2]->mutable_data()); |
| 483 | } else { |
| 484 | // Empty buffer |
| 485 | out_arr->buffers[2] = Buffer::FromString(""); |
| 486 | } |
| 487 | } |
| 488 | return Status::OK(); |
| 489 | } |
| 490 | |
| 491 | // ---------------------------------------------------------------------- |
| 492 | // Predicates and classification |
nothing calls this directly
no test coverage detected