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

Function RandomVString

cpp/src/arrow/acero/tpch_node.cc:590–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

588}
589
590Result<Datum> RandomVString(random::pcg32_fast& rng, int64_t num_rows, int32_t min_length,
591 int32_t max_length) {
592 std::uniform_int_distribution<int32_t> length_dist(min_length, max_length);
593 ARROW_ASSIGN_OR_RAISE(std::unique_ptr<Buffer> offset_buff,
594 AllocateBuffer((num_rows + 1) * sizeof(int32_t)));
595 int32_t* offsets = reinterpret_cast<int32_t*>(offset_buff->mutable_data());
596 offsets[0] = 0;
597 for (int64_t i = 1; i <= num_rows; i++) offsets[i] = offsets[i - 1] + length_dist(rng);
598 ARROW_ASSIGN_OR_RAISE(std::unique_ptr<Buffer> str_buff,
599 AllocateBuffer(offsets[num_rows]));
600 char* str = reinterpret_cast<char*>(str_buff->mutable_data());
601
602 // Spec says to pick random alphanumeric characters from a set of at least
603 // 64 symbols. Now, let's think critically here: 26 letters in the alphabet,
604 // so 52 total for upper and lower case, and 10 possible digits gives 62
605 // characters...
606 // dbgen solves this by including a space and a comma as well, so we'll
607 // copy that.
608 const char alpha_numerics[65] =
609 "0123456789abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ,";
610 std::uniform_int_distribution<int> char_dist(0, 63);
611 for (int32_t i = 0; i < offsets[num_rows]; i++) str[i] = alpha_numerics[char_dist(rng)];
612
613 ArrayData ad(utf8(), num_rows, {nullptr, std::move(offset_buff), std::move(str_buff)});
614 return ad;
615}
616
617void GeneratePhoneNumber(char* out, random::pcg32_fast& rng, int32_t country) {
618 std::uniform_int_distribution<int32_t> three_digit(100, 999);

Callers 2

S_ADDRESSMethod · 0.85
C_ADDRESSMethod · 0.85

Calls 3

ARROW_ASSIGN_OR_RAISEFunction · 0.70
AllocateBufferFunction · 0.50
mutable_dataMethod · 0.45

Tested by

no test coverage detected