| 179 | using offset_type = typename InListType::offset_type; |
| 180 | |
| 181 | static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) { |
| 182 | const auto& opts = OptionsWrapper<ListSliceOptions>::Get(ctx); |
| 183 | const ArraySpan& list_array = batch[0].array; |
| 184 | const auto* list_type = checked_cast<const BaseListType*>(list_array.type); |
| 185 | |
| 186 | // Pre-conditions |
| 187 | if (opts.start < 0 || (opts.stop.has_value() && opts.start > opts.stop.value())) { |
| 188 | return Status::Invalid( |
| 189 | "`start`(", opts.start, |
| 190 | ") should be greater than or equal to 0 and not greater than `stop`(", |
| 191 | ToString(opts.stop), ")"); |
| 192 | } |
| 193 | if (opts.step < 1) { |
| 194 | return Status::Invalid("`step` must be greater than or equal to 1, got: ", |
| 195 | opts.step); |
| 196 | } |
| 197 | |
| 198 | auto* pool = ctx->memory_pool(); |
| 199 | ARROW_ASSIGN_OR_RAISE(auto output_type_holder, ListSliceOutputType(opts, *list_type)); |
| 200 | constexpr auto kInputTypeId = InListType::type_id; |
| 201 | auto output_type = output_type_holder.GetSharedPtr(); |
| 202 | switch (output_type->id()) { |
| 203 | // The various `if constexpr` guards below avoid generating |
| 204 | // ListSlice<InListType>::BuildArray<ListBuilder> specializations |
| 205 | // that will never be invoked at runtime. |
| 206 | case Type::LIST: |
| 207 | DCHECK(kInputTypeId == Type::LIST || kInputTypeId == Type::FIXED_SIZE_LIST); |
| 208 | if constexpr (kInputTypeId == Type::LIST || |
| 209 | kInputTypeId == Type::FIXED_SIZE_LIST) { |
| 210 | return BuildArray<ListBuilder>(pool, opts, batch, output_type, out); |
| 211 | } |
| 212 | break; |
| 213 | case Type::LARGE_LIST: |
| 214 | DCHECK_EQ(kInputTypeId, Type::LARGE_LIST); |
| 215 | if constexpr (kInputTypeId == Type::LARGE_LIST) { |
| 216 | return BuildArray<LargeListBuilder>(pool, opts, batch, output_type, out); |
| 217 | } |
| 218 | break; |
| 219 | case Type::FIXED_SIZE_LIST: |
| 220 | // A fixed-size list can be produced from any list-like input |
| 221 | // if ListSliceOptions::return_fixed_size_list is set to true |
| 222 | return BuildArray<FixedSizeListBuilder>(pool, opts, batch, output_type, out); |
| 223 | case Type::LIST_VIEW: |
| 224 | DCHECK_EQ(kInputTypeId, Type::LIST_VIEW); |
| 225 | if constexpr (kInputTypeId == Type::LIST_VIEW) { |
| 226 | return BuildArray<ListViewBuilder>(pool, opts, batch, output_type, out); |
| 227 | } |
| 228 | break; |
| 229 | case Type::LARGE_LIST_VIEW: |
| 230 | DCHECK_EQ(kInputTypeId, Type::LARGE_LIST_VIEW); |
| 231 | if constexpr (kInputTypeId == Type::LARGE_LIST_VIEW) { |
| 232 | return BuildArray<LargeListViewBuilder>(pool, opts, batch, output_type, out); |
| 233 | } |
| 234 | break; |
| 235 | default: |
| 236 | break; |
| 237 | } |
| 238 | Unreachable(); |
nothing calls this directly
no test coverage detected