| 31 | namespace parquet { |
| 32 | |
| 33 | TEST(PageIndex, ReadOffsetIndex) { |
| 34 | std::string dir_string(parquet::test::get_data_dir()); |
| 35 | std::string path = dir_string + "/alltypes_tiny_pages.parquet"; |
| 36 | auto reader = ParquetFileReader::OpenFile(path, false); |
| 37 | auto file_metadata = reader->metadata(); |
| 38 | |
| 39 | // Get offset index location to column 0 of row group 0. |
| 40 | const int row_group_id = 0; |
| 41 | const int column_id = 0; |
| 42 | ASSERT_LT(row_group_id, file_metadata->num_row_groups()); |
| 43 | ASSERT_LT(column_id, file_metadata->num_columns()); |
| 44 | auto index_location = file_metadata->RowGroup(row_group_id) |
| 45 | ->ColumnChunk(column_id) |
| 46 | ->GetOffsetIndexLocation(); |
| 47 | ASSERT_TRUE(index_location.has_value()); |
| 48 | |
| 49 | // Read serialized offset index from the file. |
| 50 | std::shared_ptr<::arrow::io::RandomAccessFile> source; |
| 51 | PARQUET_ASSIGN_OR_THROW(source, ::arrow::io::ReadableFile::Open(path)); |
| 52 | PARQUET_ASSIGN_OR_THROW(auto buffer, |
| 53 | source->ReadAt(index_location->offset, index_location->length)); |
| 54 | PARQUET_THROW_NOT_OK(source->Close()); |
| 55 | |
| 56 | // Deserialize offset index. |
| 57 | auto properties = default_reader_properties(); |
| 58 | std::unique_ptr<OffsetIndex> offset_index = OffsetIndex::Make( |
| 59 | buffer->data(), static_cast<uint32_t>(buffer->size()), properties); |
| 60 | |
| 61 | // Verify only partial data as it contains 325 pages in total. |
| 62 | const size_t num_pages = 325; |
| 63 | const std::vector<size_t> page_indices = {0, 100, 200, 300}; |
| 64 | const std::vector<PageLocation> page_locations = { |
| 65 | PageLocation{4, 109, 0}, PageLocation{11480, 133, 2244}, |
| 66 | PageLocation{22980, 133, 4494}, PageLocation{34480, 133, 6744}}; |
| 67 | |
| 68 | ASSERT_EQ(num_pages, offset_index->page_locations().size()); |
| 69 | for (size_t i = 0; i < page_indices.size(); ++i) { |
| 70 | size_t page_id = page_indices.at(i); |
| 71 | const auto& read_page_location = offset_index->page_locations().at(page_id); |
| 72 | const auto& expected_page_location = page_locations.at(i); |
| 73 | ASSERT_EQ(expected_page_location.offset, read_page_location.offset); |
| 74 | ASSERT_EQ(expected_page_location.compressed_page_size, |
| 75 | read_page_location.compressed_page_size); |
| 76 | ASSERT_EQ(expected_page_location.first_row_index, read_page_location.first_row_index); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | template <typename DType, typename T = typename DType::c_type> |
| 81 | void TestReadTypedColumnIndex(const std::string& file_name, int column_id, |
nothing calls this directly
no test coverage detected