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

Function TestWriteOffsetIndex

cpp/src/parquet/page_index_test.cc:422–470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420}
421
422void TestWriteOffsetIndex(bool write_size_stats) {
423 /// Create offset index via the OffsetIndexBuilder interface.
424 auto builder = OffsetIndexBuilder::Make();
425 const size_t num_pages = 5;
426 const std::vector<int64_t> offsets = {100, 200, 300, 400, 500};
427 const std::vector<int32_t> page_sizes = {1024, 2048, 3072, 4096, 8192};
428 const std::vector<int64_t> first_row_indices = {0, 10000, 20000, 30000, 40000};
429 const std::vector<int64_t> unencoded_byte_array_lengths = {1111, 2222, 0, 3333, 4444};
430 for (size_t i = 0; i < num_pages; ++i) {
431 auto unencoded_byte_array_length =
432 write_size_stats ? std::make_optional(unencoded_byte_array_lengths[i])
433 : std::nullopt;
434 builder->AddPage(offsets[i], page_sizes[i], first_row_indices[i],
435 unencoded_byte_array_length);
436 }
437 const int64_t final_position = 4096;
438 builder->Finish(final_position);
439
440 std::vector<std::unique_ptr<OffsetIndex>> offset_indexes;
441 /// 1st element is the offset index just built.
442 offset_indexes.emplace_back(builder->Build());
443 /// 2nd element is the offset index restored by serialize-then-deserialize round trip.
444 auto sink = CreateOutputStream();
445 builder->WriteTo(sink.get());
446 PARQUET_ASSIGN_OR_THROW(auto buffer, sink->Finish());
447 offset_indexes.emplace_back(OffsetIndex::Make(buffer->data(),
448 static_cast<uint32_t>(buffer->size()),
449 default_reader_properties()));
450
451 /// Verify the data of the offset index.
452 for (const auto& offset_index : offset_indexes) {
453 ASSERT_EQ(num_pages, offset_index->page_locations().size());
454 if (write_size_stats) {
455 ASSERT_EQ(num_pages, offset_index->unencoded_byte_array_data_bytes().size());
456 } else {
457 ASSERT_TRUE(offset_index->unencoded_byte_array_data_bytes().empty());
458 }
459 for (size_t i = 0; i < num_pages; ++i) {
460 const auto& page_location = offset_index->page_locations().at(i);
461 ASSERT_EQ(offsets[i] + final_position, page_location.offset);
462 ASSERT_EQ(page_sizes[i], page_location.compressed_page_size);
463 ASSERT_EQ(first_row_indices[i], page_location.first_row_index);
464 if (write_size_stats) {
465 ASSERT_EQ(unencoded_byte_array_lengths[i],
466 offset_index->unencoded_byte_array_data_bytes()[i]);
467 }
468 }
469 }
470}
471
472TEST(PageIndex, WriteOffsetIndexWithoutSizeStats) {
473 TestWriteOffsetIndex(/*write_size_stats=*/false);

Callers 1

TESTFunction · 0.85

Calls 12

CreateOutputStreamFunction · 0.85
emplace_backMethod · 0.80
MakeFunction · 0.70
AddPageMethod · 0.45
FinishMethod · 0.45
BuildMethod · 0.45
WriteToMethod · 0.45
getMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected