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