| 487 | } |
| 488 | |
| 489 | void TestFullRoundtrip(int64_t num_values, int64_t null_count) { |
| 490 | this->GenerateData(num_values); |
| 491 | |
| 492 | // compute statistics for the whole batch |
| 493 | auto expected_stats = MakeStatistics<TestType>(this->schema_.Column(0)); |
| 494 | expected_stats->Update(this->values_ptr_, num_values - null_count, null_count); |
| 495 | |
| 496 | auto sink = CreateOutputStream(); |
| 497 | auto gnode = std::static_pointer_cast<GroupNode>(this->node_); |
| 498 | std::shared_ptr<WriterProperties> writer_properties = |
| 499 | WriterProperties::Builder().enable_statistics("column")->build(); |
| 500 | auto file_writer = ParquetFileWriter::Open(sink, gnode, writer_properties); |
| 501 | auto row_group_writer = file_writer->AppendRowGroup(); |
| 502 | auto column_writer = |
| 503 | static_cast<TypedColumnWriter<TestType>*>(row_group_writer->NextColumn()); |
| 504 | |
| 505 | // simulate the case when data comes from multiple buffers, |
| 506 | // in which case special care is necessary for FLBA/ByteArray types |
| 507 | for (int i = 0; i < 2; i++) { |
| 508 | int64_t batch_num_values = i ? num_values - num_values / 2 : num_values / 2; |
| 509 | int64_t batch_null_count = i ? null_count : 0; |
| 510 | DCHECK(null_count <= num_values); // avoid too much headache |
| 511 | std::vector<int16_t> definition_levels(batch_null_count, 0); |
| 512 | definition_levels.insert(definition_levels.end(), |
| 513 | batch_num_values - batch_null_count, 1); |
| 514 | auto beg = this->values_.begin() + i * num_values / 2; |
| 515 | auto end = beg + batch_num_values; |
| 516 | std::vector<c_type> batch = GetDeepCopy(std::vector<c_type>(beg, end)); |
| 517 | c_type* batch_values_ptr = GetValuesPointer(batch); |
| 518 | column_writer->WriteBatch(batch_num_values, definition_levels.data(), nullptr, |
| 519 | batch_values_ptr); |
| 520 | DeepFree(batch); |
| 521 | } |
| 522 | column_writer->Close(); |
| 523 | row_group_writer->Close(); |
| 524 | file_writer->Close(); |
| 525 | |
| 526 | ASSERT_OK_AND_ASSIGN(auto buffer, sink->Finish()); |
| 527 | auto source = std::make_shared<::arrow::io::BufferReader>(buffer); |
| 528 | auto file_reader = ParquetFileReader::Open(source); |
| 529 | auto rg_reader = file_reader->RowGroup(0); |
| 530 | auto column_chunk = rg_reader->metadata()->ColumnChunk(0); |
| 531 | if (!column_chunk->is_stats_set()) return; |
| 532 | std::shared_ptr<Statistics> stats = column_chunk->statistics(); |
| 533 | // check values after serialization + deserialization |
| 534 | EXPECT_EQ(null_count, stats->null_count()); |
| 535 | EXPECT_EQ(num_values - null_count, stats->num_values()); |
| 536 | EXPECT_TRUE(expected_stats->HasMinMax()); |
| 537 | EXPECT_EQ(expected_stats->EncodeMin(), stats->EncodeMin()); |
| 538 | EXPECT_EQ(expected_stats->EncodeMax(), stats->EncodeMax()); |
| 539 | |
| 540 | std::shared_ptr<EncodedStatistics> enc_stats = column_chunk->encoded_statistics(); |
| 541 | EXPECT_EQ(null_count, enc_stats->null_count); |
| 542 | EXPECT_TRUE(enc_stats->has_min); |
| 543 | EXPECT_TRUE(enc_stats->has_max); |
| 544 | EXPECT_EQ(expected_stats->EncodeMin(), enc_stats->min()); |
| 545 | EXPECT_EQ(expected_stats->EncodeMax(), enc_stats->max()); |
| 546 | EXPECT_EQ(enc_stats->is_min_value_exact, std::make_optional(true)); |
no test coverage detected