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

Method EnsureInitialized

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

Source from the content-addressed store, hash-verified

279static TpchPseudotext g_text;
280
281Status TpchPseudotext::EnsureInitialized(random::pcg32_fast& rng) {
282 if (done_.load()) return Status::OK();
283
284 {
285 std::lock_guard<std::mutex> lock(text_guard_);
286 if (!text_) {
287 ARROW_ASSIGN_OR_RAISE(text_, AllocateBuffer(kTextBytes));
288 }
289 }
290 char* out = reinterpret_cast<char*>(text_->mutable_data());
291 char temp_buff[kChunkSize];
292
293 while (!done_.load()) {
294 int64_t known_valid_offset = 0;
295 int64_t try_offset = 0;
296 while (GenerateSentence(try_offset, rng, temp_buff)) known_valid_offset = try_offset;
297
298 bool last_one;
299 int64_t offset;
300 int64_t memcpy_size;
301 {
302 std::lock_guard<std::mutex> lock(text_guard_);
303 if (done_.load()) return Status::OK();
304 int64_t bytes_remaining = kTextBytes - generated_offset_;
305 memcpy_size = std::min(known_valid_offset, bytes_remaining);
306 offset = generated_offset_;
307 generated_offset_ += memcpy_size;
308 last_one = generated_offset_ == kTextBytes;
309 }
310 std::memcpy(out + offset, temp_buff, memcpy_size);
311 if (last_one) done_.store(true);
312 }
313 return Status::OK();
314}
315
316Result<Datum> TpchPseudotext::GenerateComments(size_t num_comments, size_t min_length,
317 size_t max_length,

Callers

nothing calls this directly

Calls 6

storeMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
OKFunction · 0.50
AllocateBufferFunction · 0.50
loadMethod · 0.45
mutable_dataMethod · 0.45

Tested by

no test coverage detected