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

Function GenRandomUniqueRecords

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

Generate random arrays given list of data types and null probabilities. Make sure that all generated records are unique. The actual number of generated records may be lower than desired because duplicates will be removed without replacement.

Source from the content-addressed store, hash-verified

504// will be removed without replacement.
505//
506std::vector<std::shared_ptr<Array>> GenRandomUniqueRecords(
507 Random64Bit& rng, const RandomDataTypeVector& data_types, int num_desired,
508 int* num_actual) {
509 std::vector<std::shared_ptr<Array>> result =
510 GenRandomRecords(rng, data_types.data_types, num_desired);
511
512 ExecContext* ctx = default_exec_context();
513 std::vector<TypeHolder> val_types;
514 for (size_t i = 0; i < result.size(); ++i) {
515 val_types.push_back(result[i]->type());
516 }
517 RowEncoder encoder;
518 encoder.Init(val_types, ctx);
519 ExecBatch batch({}, num_desired);
520 batch.values.resize(result.size());
521 for (size_t i = 0; i < result.size(); ++i) {
522 batch.values[i] = result[i];
523 }
524 Status status = encoder.EncodeAndAppend(ExecSpan(batch));
525 ARROW_DCHECK(status.ok());
526
527 std::unordered_map<std::string, int> uniques;
528 std::vector<int32_t> ids;
529 for (int i = 0; i < num_desired; ++i) {
530 if (uniques.find(encoder.encoded_row(i)) == uniques.end()) {
531 uniques.insert(std::make_pair(encoder.encoded_row(i), i));
532 ids.push_back(i);
533 }
534 }
535 *num_actual = static_cast<int>(uniques.size());
536
537 std::vector<std::shared_ptr<Array>> output;
538 TakeUsingVector(ctx, result, ids, &output);
539 return output;
540}
541
542std::vector<bool> NullInKey(const std::vector<JoinKeyCmp>& cmp,
543 const std::vector<std::shared_ptr<Array>>& key) {

Callers 1

GenRandomJoinTablesFunction · 0.85

Calls 14

GenRandomRecordsFunction · 0.85
default_exec_contextFunction · 0.85
TakeUsingVectorFunction · 0.85
push_backMethod · 0.80
resizeMethod · 0.80
EncodeAndAppendMethod · 0.80
ExecSpanFunction · 0.50
sizeMethod · 0.45
typeMethod · 0.45
InitMethod · 0.45
okMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected