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

Function GenRandomJoinTables

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

Source from the content-addressed store, hash-verified

569}
570
571void GenRandomJoinTables(ExecContext* ctx, Random64Bit& rng, int num_rows_l,
572 int num_rows_r, int num_keys_common, int num_keys_left,
573 int num_keys_right, const RandomDataTypeVector& key_types,
574 const RandomDataTypeVector& payload_left_types,
575 const RandomDataTypeVector& payload_right_types,
576 std::vector<int32_t>* key_id_l, std::vector<int32_t>* key_id_r,
577 std::vector<std::shared_ptr<Array>>* left,
578 std::vector<std::shared_ptr<Array>>* right) {
579 // Generate random keys dictionary
580 //
581 int num_keys_desired = num_keys_left + num_keys_right - num_keys_common;
582 int num_keys_actual = 0;
583 std::vector<std::shared_ptr<Array>> keys =
584 GenRandomUniqueRecords(rng, key_types, num_keys_desired, &num_keys_actual);
585
586 // There will be three dictionary id ranges:
587 // - common keys [0..num_keys_common-1]
588 // - keys on right that are not on left [num_keys_common..num_keys_right-1]
589 // - keys on left that are not on right [num_keys_right..num_keys_actual-1]
590 //
591 num_keys_common = static_cast<int>(static_cast<int64_t>(num_keys_common) *
592 num_keys_actual / num_keys_desired);
593 num_keys_right = static_cast<int>(static_cast<int64_t>(num_keys_right) *
594 num_keys_actual / num_keys_desired);
595 ARROW_DCHECK(num_keys_right >= num_keys_common);
596 num_keys_left = num_keys_actual - num_keys_right + num_keys_common;
597 if (num_keys_left == 0) {
598 ARROW_DCHECK(num_keys_common == 0 && num_keys_right > 0);
599 ++num_keys_left;
600 ++num_keys_common;
601 }
602 if (num_keys_right == 0) {
603 ARROW_DCHECK(num_keys_common == 0 && num_keys_left > 0);
604 ++num_keys_right;
605 ++num_keys_common;
606 }
607 ARROW_DCHECK(num_keys_left >= num_keys_common);
608 ARROW_DCHECK(num_keys_left + num_keys_right - num_keys_common == num_keys_actual);
609
610 key_id_l->resize(num_rows_l);
611 for (int i = 0; i < num_rows_l; ++i) {
612 (*key_id_l)[i] = rng.from_range(0, num_keys_left - 1);
613 if ((*key_id_l)[i] >= num_keys_common) {
614 (*key_id_l)[i] += num_keys_right - num_keys_common;
615 }
616 }
617
618 key_id_r->resize(num_rows_r);
619 for (int i = 0; i < num_rows_r; ++i) {
620 (*key_id_r)[i] = rng.from_range(0, num_keys_right - 1);
621 }
622
623 std::vector<std::shared_ptr<Array>> key_l;
624 std::vector<std::shared_ptr<Array>> key_r;
625 TakeUsingVector(ctx, keys, *key_id_l, &key_l);
626 TakeUsingVector(ctx, keys, *key_id_r, &key_r);
627 std::vector<std::shared_ptr<Array>> payload_l =
628 GenRandomRecords(rng, payload_left_types.data_types, num_rows_l);

Callers 1

TESTFunction · 0.85

Calls 6

GenRandomUniqueRecordsFunction · 0.85
TakeUsingVectorFunction · 0.85
GenRandomRecordsFunction · 0.85
resizeMethod · 0.80
from_rangeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected