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

Method TestWriteAndRead

cpp/src/parquet/reader_test.cc:2025–2079  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2023 }
2024
2025 void TestWriteAndRead(std::shared_ptr<const LogicalType> type, bool write_arrow) {
2026 ASSERT_NO_FATAL_FAILURE(WriteTestData(type, write_arrow));
2027
2028 auto in_file = std::make_shared<::arrow::io::BufferReader>(file_buf);
2029
2030 ReaderProperties reader_props;
2031 reader_props.enable_buffered_stream();
2032 reader_props.set_buffer_size(64);
2033 auto file_reader = ParquetFileReader::Open(in_file, reader_props);
2034
2035 // Check that the geometry statistics are correctly written and read
2036 auto metadata = file_reader->metadata();
2037 ASSERT_TRUE(type->Equals(*metadata->schema()->Column(0)->logical_type()));
2038
2039 auto page_index_reader = file_reader->GetPageIndexReader();
2040 int num_row_groups = metadata->num_row_groups();
2041 int64_t start_index = 0;
2042 for (int i = 0; i < num_row_groups; i++) {
2043 auto row_group_metadata = metadata->RowGroup(i);
2044 auto column_chunk_metadata = row_group_metadata->ColumnChunk(0);
2045 auto geo_stats = column_chunk_metadata->geo_statistics();
2046 ASSERT_NO_FATAL_FAILURE(CheckGeoStatistics(type, geo_stats, start_index,
2047 row_group_metadata->num_rows()));
2048 start_index += row_group_metadata->num_rows();
2049 }
2050
2051 // Check the geometry values
2052 int64_t total_values_read = 0;
2053 for (int i = 0; i < num_row_groups; i++) {
2054 auto row_group = file_reader->RowGroup(i);
2055 std::shared_ptr<ByteArrayReader> reader =
2056 std::static_pointer_cast<ByteArrayReader>(row_group->Column(0));
2057 while (reader->HasNext()) {
2058 std::vector<ByteArray> out(kNumRows);
2059 int64_t values_read = 0;
2060 int64_t levels_read =
2061 reader->ReadBatch(kNumRows, nullptr, nullptr, out.data(), &values_read);
2062 ASSERT_GE(levels_read, 1);
2063 ASSERT_GE(values_read, 1);
2064
2065 // Check the batch
2066 for (int64_t i = 0; i < values_read; i++) {
2067 const ByteArray& value = out[i];
2068 auto xy = test::GetWKBPointCoordinateXY(value);
2069 EXPECT_TRUE(xy.has_value());
2070 auto expected_x = static_cast<double>(i + total_values_read);
2071 auto expected_y = static_cast<double>(i + 1 + total_values_read);
2072 EXPECT_EQ(*xy, (std::pair<double, double>(expected_x, expected_y)));
2073 }
2074
2075 total_values_read += values_read;
2076 }
2077 }
2078 EXPECT_EQ(kNumRows, total_values_read);
2079 }
2080
2081 void CheckGeoStatistics(std::shared_ptr<const LogicalType> type,
2082 std::shared_ptr<geospatial::GeoStatistics> geom_stats,

Callers

nothing calls this directly

Calls 15

GetWKBPointCoordinateXYFunction · 0.85
set_buffer_sizeMethod · 0.80
geo_statisticsMethod · 0.80
metadataMethod · 0.45
EqualsMethod · 0.45
ColumnMethod · 0.45
schemaMethod · 0.45
GetPageIndexReaderMethod · 0.45
num_row_groupsMethod · 0.45
RowGroupMethod · 0.45
ColumnChunkMethod · 0.45
num_rowsMethod · 0.45

Tested by

no test coverage detected