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

Function TakeUsingVector

cpp/src/arrow/acero/hash_join_node_test.cc:446–499  ·  view source on GitHub ↗

Index < 0 means appending null values to all columns.

Source from the content-addressed store, hash-verified

444// Index < 0 means appending null values to all columns.
445//
446void TakeUsingVector(ExecContext* ctx, const std::vector<std::shared_ptr<Array>>& input,
447 const std::vector<int32_t> indices,
448 std::vector<std::shared_ptr<Array>>* result) {
449 ASSERT_OK_AND_ASSIGN(
450 std::shared_ptr<Buffer> buf,
451 AllocateBuffer(indices.size() * sizeof(int32_t), ctx->memory_pool()));
452 int32_t* buf_indices = reinterpret_cast<int32_t*>(buf->mutable_data());
453 bool has_null_rows = false;
454 for (size_t i = 0; i < indices.size(); ++i) {
455 if (indices[i] < 0) {
456 buf_indices[i] = 0;
457 has_null_rows = true;
458 } else {
459 buf_indices[i] = indices[i];
460 }
461 }
462 std::shared_ptr<Array> indices_array = MakeArray(ArrayData::Make(
463 int32(), indices.size(), {nullptr, std::move(buf)}, /*null_count=*/0));
464
465 result->resize(input.size());
466 for (size_t i = 0; i < result->size(); ++i) {
467 ASSERT_OK_AND_ASSIGN(Datum new_array, Take(input[i], indices_array));
468 (*result)[i] = new_array.make_array();
469 }
470 if (has_null_rows) {
471 for (size_t i = 0; i < result->size(); ++i) {
472 if ((*result)[i]->data()->buffers[0] == NULLPTR) {
473 ASSERT_OK_AND_ASSIGN(std::shared_ptr<Buffer> null_buf,
474 AllocateBitmap(indices.size(), ctx->memory_pool()));
475 uint8_t* non_nulls = null_buf->mutable_data();
476 memset(non_nulls, 0xFF, bit_util::BytesForBits(indices.size()));
477 if ((*result)[i]->data()->buffers.size() == 2) {
478 (*result)[i] = MakeArray(
479 ArrayData::Make((*result)[i]->type(), indices.size(),
480 {std::move(null_buf), (*result)[i]->data()->buffers[1]}));
481 } else {
482 (*result)[i] = MakeArray(
483 ArrayData::Make((*result)[i]->type(), indices.size(),
484 {std::move(null_buf), (*result)[i]->data()->buffers[1],
485 (*result)[i]->data()->buffers[2]}));
486 }
487 }
488 (*result)[i]->data()->SetNullCount(kUnknownNullCount);
489 }
490 for (size_t i = 0; i < indices.size(); ++i) {
491 if (indices[i] < 0) {
492 for (size_t col = 0; col < result->size(); ++col) {
493 uint8_t* non_nulls = (*result)[col]->data()->buffers[0]->mutable_data();
494 bit_util::ClearBit(non_nulls, i);
495 }
496 }
497 }
498 }
499}
500
501// Generate random arrays given list of data types and null probabilities.
502// Make sure that all generated records are unique.

Callers 3

GenRandomUniqueRecordsFunction · 0.85
GenRandomJoinTablesFunction · 0.85

Calls 14

AllocateBitmapFunction · 0.85
BytesForBitsFunction · 0.85
ClearBitFunction · 0.85
resizeMethod · 0.80
make_arrayMethod · 0.80
ASSERT_OK_AND_ASSIGNFunction · 0.70
AllocateBufferFunction · 0.50
MakeArrayFunction · 0.50
MakeFunction · 0.50
sizeMethod · 0.45
memory_poolMethod · 0.45
mutable_dataMethod · 0.45

Tested by

no test coverage detected