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

Function TestRandomInput

cpp/src/arrow/chunked_array_test.cc:588–627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

586 }
587
588 void TestRandomInput(int32_t num_chunks, int64_t chunked_array_len) {
589 random::pcg64 rng(42);
590
591 // Generate random chunk offsets...
592 auto offsets = GenChunkedArrayOffsets(rng, num_chunks, chunked_array_len);
593 ASSERT_EQ(offsets.size(), static_cast<size_t>(num_chunks) + 1);
594 // ...and ensure there is at least one empty chunk.
595 std::uniform_int_distribution<int32_t> chunk_index_gen(
596 1, static_cast<int32_t>(num_chunks - 1));
597 auto chunk_index = chunk_index_gen(rng);
598 offsets[chunk_index] = offsets[chunk_index - 1];
599
600 // Generate random query array of logical indices...
601 const auto num_logical_indices = 3 * static_cast<int64_t>(num_chunks) / 2;
602 std::vector<IndexType> logical_index_vec;
603 logical_index_vec.reserve(num_logical_indices);
604 std::uniform_int_distribution<uint64_t> logical_index_gen(1, kMaxValidIndex);
605 for (int64_t i = 0; i < num_logical_indices; i++) {
606 const auto index = static_cast<IndexType>(logical_index_gen(rng));
607 logical_index_vec.push_back(index);
608 }
609 // ...and sprinkle some extreme logical index values.
610 std::uniform_int_distribution<int64_t> position_gen(0, logical_index_vec.size() - 1);
611 for (int i = 0; i < 2; i++) {
612 auto max_valid_index =
613 std::min(kMaxValidIndex, static_cast<uint64_t>(chunked_array_len));
614 // zero and last valid logical index
615 logical_index_vec[position_gen(rng)] = 0;
616 logical_index_vec[position_gen(rng)] = static_cast<IndexType>(max_valid_index - 1);
617 // out of bounds indices
618 logical_index_vec[position_gen(rng)] = static_cast<IndexType>(max_valid_index);
619 if (max_valid_index < kMaxValidIndex) {
620 logical_index_vec[position_gen(rng)] =
621 static_cast<IndexType>(max_valid_index + 1);
622 }
623 }
624
625 ChunkResolver resolver(std::move(offsets));
626 CheckResolveMany(resolver, logical_index_vec);
627 }
628
629 void TestRandomInput() {
630 const int64_t num_chunks = static_cast<int64_t>(

Callers

nothing calls this directly

Calls 3

push_backMethod · 0.80
sizeMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected