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

Method TestWriteAndRead

cpp/src/parquet/reader_test.cc:2301–2355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2299 }
2300
2301 void TestWriteAndRead(std::shared_ptr<const LogicalType> type, bool write_arrow) {
2302 ASSERT_NO_FATAL_FAILURE(WriteTestData(type, write_arrow));
2303
2304 auto in_file = std::make_shared<::arrow::io::BufferReader>(file_buf);
2305
2306 ReaderProperties reader_props;
2307 reader_props.enable_buffered_stream();
2308 reader_props.set_buffer_size(64);
2309 auto file_reader = ParquetFileReader::Open(in_file, reader_props);
2310
2311 // Check that the geometry statistics are correctly written and read
2312 auto metadata = file_reader->metadata();
2313 ASSERT_TRUE(type->Equals(*metadata->schema()->Column(0)->logical_type()));
2314
2315 auto page_index_reader = file_reader->GetPageIndexReader();
2316 int num_row_groups = metadata->num_row_groups();
2317 int64_t start_index = 0;
2318 for (int i = 0; i < num_row_groups; i++) {
2319 auto row_group_metadata = metadata->RowGroup(i);
2320 auto column_chunk_metadata = row_group_metadata->ColumnChunk(0);
2321 auto geo_stats = column_chunk_metadata->geo_statistics();
2322 ASSERT_NO_FATAL_FAILURE(CheckGeoStatistics(type, geo_stats, start_index,
2323 row_group_metadata->num_rows()));
2324 start_index += row_group_metadata->num_rows();
2325 }
2326
2327 // Check the geometry values
2328 int64_t total_values_read = 0;
2329 for (int i = 0; i < num_row_groups; i++) {
2330 auto row_group = file_reader->RowGroup(i);
2331 std::shared_ptr<ByteArrayReader> reader =
2332 std::static_pointer_cast<ByteArrayReader>(row_group->Column(0));
2333 while (reader->HasNext()) {
2334 std::vector<ByteArray> out(kNumRows);
2335 int64_t values_read = 0;
2336 int64_t levels_read =
2337 reader->ReadBatch(kNumRows, nullptr, nullptr, out.data(), &values_read);
2338 ASSERT_GE(levels_read, 1);
2339 ASSERT_GE(values_read, 1);
2340
2341 // Check the batch
2342 for (int64_t i = 0; i < values_read; i++) {
2343 const ByteArray& value = out[i];
2344 auto xy = test::GetWKBPointCoordinateXY(value);
2345 EXPECT_TRUE(xy.has_value());
2346 auto expected_x = static_cast<double>(i + total_values_read);
2347 auto expected_y = static_cast<double>(i + 1 + total_values_read);
2348 EXPECT_EQ(*xy, (std::pair<double, double>(expected_x, expected_y)));
2349 }
2350
2351 total_values_read += values_read;
2352 }
2353 }
2354 EXPECT_EQ(kNumRows, total_values_read);
2355 }
2356
2357 void CheckGeoStatistics(std::shared_ptr<const LogicalType> type,
2358 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