| 57 | using ArrayType = typename TypeTraits<InType>::ArrayType; |
| 58 | |
| 59 | static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) { |
| 60 | using GetView = GetViewType<InType>; |
| 61 | |
| 62 | if (ctx->state() == nullptr) { |
| 63 | return Status::Invalid("NthToIndices requires PartitionNthOptions"); |
| 64 | } |
| 65 | const auto& options = PartitionNthToIndicesState::Get(ctx); |
| 66 | |
| 67 | ArrayType arr(batch[0].array.ToArrayData()); |
| 68 | |
| 69 | const int64_t pivot = options.pivot; |
| 70 | if (pivot > arr.length()) { |
| 71 | return Status::IndexError("NthToIndices index out of bound"); |
| 72 | } |
| 73 | ArrayData* out_arr = out->array_data().get(); |
| 74 | std::span<uint64_t> out_span{out_arr->GetMutableValues<uint64_t>(1), |
| 75 | static_cast<size_t>(arr.length())}; |
| 76 | std::iota(out_span.begin(), out_span.end(), 0); |
| 77 | if (pivot == arr.length()) { |
| 78 | return Status::OK(); |
| 79 | } |
| 80 | const auto p = PartitionNullsAndNans<ArrayType, NonStablePartitioner>( |
| 81 | out_span, arr, 0, options.null_placement); |
| 82 | auto nth_begin = out_span.data() + pivot; |
| 83 | auto non_null_begin = p.non_null_like_begin(); |
| 84 | auto non_null_end = p.non_null_like_end(); |
| 85 | if (nth_begin >= non_null_begin && nth_begin < non_null_end) { |
| 86 | std::nth_element(non_null_begin, nth_begin, non_null_end, |
| 87 | [&arr](uint64_t left, uint64_t right) { |
| 88 | const auto lval = GetView::LogicalValue(arr.GetView(left)); |
| 89 | const auto rval = GetView::LogicalValue(arr.GetView(right)); |
| 90 | return lval < rval; |
| 91 | }); |
| 92 | } |
| 93 | return Status::OK(); |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | template <typename OutType> |
nothing calls this directly
no test coverage detected