| 314 | } |
| 315 | |
| 316 | Result<Datum> TpchPseudotext::GenerateComments(size_t num_comments, size_t min_length, |
| 317 | size_t max_length, |
| 318 | random::pcg32_fast& rng) { |
| 319 | RETURN_NOT_OK(EnsureInitialized(rng)); |
| 320 | std::uniform_int_distribution<size_t> length_dist(min_length, max_length); |
| 321 | ARROW_ASSIGN_OR_RAISE(std::unique_ptr<Buffer> offset_buffer, |
| 322 | AllocateBuffer(sizeof(int32_t) * (num_comments + 1))); |
| 323 | int32_t* offsets = reinterpret_cast<int32_t*>(offset_buffer->mutable_data()); |
| 324 | offsets[0] = 0; |
| 325 | for (size_t i = 1; i <= num_comments; i++) |
| 326 | offsets[i] = offsets[i - 1] + static_cast<int32_t>(length_dist(rng)); |
| 327 | |
| 328 | ARROW_ASSIGN_OR_RAISE(std::unique_ptr<Buffer> comment_buffer, |
| 329 | AllocateBuffer(offsets[num_comments])); |
| 330 | char* comments = reinterpret_cast<char*>(comment_buffer->mutable_data()); |
| 331 | for (size_t i = 0; i < num_comments; i++) { |
| 332 | size_t length = offsets[i + 1] - offsets[i]; |
| 333 | std::uniform_int_distribution<size_t> offset_dist(0, kTextBytes - length); |
| 334 | size_t offset_in_text = offset_dist(rng); |
| 335 | std::memcpy(comments + offsets[i], text_->data() + offset_in_text, length); |
| 336 | } |
| 337 | ArrayData ad(utf8(), num_comments, |
| 338 | {nullptr, std::move(offset_buffer), std::move(comment_buffer)}); |
| 339 | return ad; |
| 340 | } |
| 341 | |
| 342 | bool TpchPseudotext::GenerateWord(int64_t& offset, random::pcg32_fast& rng, char* arr, |
| 343 | const char** words, size_t num_choices) { |
no test coverage detected