MCPcopy Create free account
hub / github.com/apache/arrow / Exec

Method Exec

cpp/src/arrow/compute/kernels/vector_replace.cc:391–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

389template <typename Type>
390struct ReplaceMaskChunked {
391 static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
392 const Datum& mask = batch[1];
393 const Datum& replacements = batch[2];
394
395 // TODO(wesm): these assertions that the arguments cannot be ChunkedArray
396 // should happen someplace more generic, not here
397 if (!mask.is_array() && !mask.is_scalar()) {
398 return Status::Invalid("Mask must be array or scalar, not ", batch[1].ToString());
399 }
400
401 if (!replacements.is_array() && !replacements.is_scalar()) {
402 return Status::Invalid("Replacements must be array or scalar, not ",
403 replacements.ToString());
404 }
405
406 const ChunkedArray& arr = *batch[0].chunked_array();
407
408 RETURN_NOT_OK(CheckReplaceMaskInputs(*arr.type(), arr.length(), GetExecValue(mask),
409 *replacements.type(), replacements.length(),
410 replacements.is_arraylike()));
411
412 ExecValue replacements_val = GetExecValue(replacements);
413
414 // Chunked array
415 ArrayVector output_chunks;
416 output_chunks.reserve(arr.num_chunks());
417
418 int64_t mask_offset = 0;
419 int64_t replacements_offset = 0;
420 for (const std::shared_ptr<Array>& chunk : arr.chunks()) {
421 if (chunk->length() == 0) continue;
422 // Allocate a new array
423 ExecResult chunk_result;
424 if (is_fixed_width(out->type()->id())) {
425 auto chunk_out = std::make_shared<ArrayData>(chunk->type(), chunk->length());
426 ArrayData* chunk_out_arr = chunk_out.get();
427 RETURN_NOT_OK(util::internal::PreallocateFixedWidthArrayData(
428 ctx, chunk->length(), /*source=*/*chunk->data(),
429 /*allocate_validity=*/true, chunk_out_arr));
430 chunk_result.value = chunk_out;
431 }
432 if (batch[1].is_scalar()) {
433 ARROW_ASSIGN_OR_RAISE(
434 replacements_offset,
435 ReplaceMaskImpl<Type>::ExecScalarMask(
436 ctx, *chunk->data(), batch[1].scalar_as<BooleanScalar>(),
437 replacements_val, replacements_offset, &chunk_result));
438 } else {
439 ARROW_ASSIGN_OR_RAISE(replacements_offset,
440 ReplaceMaskImpl<Type>::ExecArrayMask(
441 ctx, *chunk->data(), *batch[1].array(), mask_offset,
442 replacements_val, replacements_offset, &chunk_result));
443 }
444 output_chunks.push_back(MakeArray(chunk_result.array_data()));
445 mask_offset += chunk->length();
446 }
447
448 return ChunkedArray::Make(std::move(output_chunks), out->type()).Value(out);

Callers

nothing calls this directly

Calls 15

CheckReplaceMaskInputsFunction · 0.85
GetExecValueFunction · 0.85
is_fixed_widthFunction · 0.85
is_arrayMethod · 0.80
is_scalarMethod · 0.80
chunked_arrayMethod · 0.80
push_backMethod · 0.80
array_dataMethod · 0.80
MakeArrayFunction · 0.70
InvalidFunction · 0.50
ARROW_ASSIGN_OR_RAISEFunction · 0.50

Tested by

no test coverage detected