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

Method TestMergeNullCount

cpp/src/parquet/statistics_test.cc:749–791  ·  view source on GitHub ↗

Default statistics should have null_count even if no nulls is written. However, if statistics is created from thrift message, it might not have null_count. Merging statistics from such page will result in an invalid null_count as well.

Source from the content-addressed store, hash-verified

747 // have null_count. Merging statistics from such page will result in an
748 // invalid null_count as well.
749 void TestMergeNullCount() {
750 this->GenerateData(/*num_values=*/1000);
751
752 // Page should have null-count even if no nulls
753 std::shared_ptr<TypedStatistics<TestType>> statistics1;
754 {
755 statistics1 = MakeStatistics<TestType>(this->schema_.Column(0));
756 statistics1->Update(this->values_ptr_, /*num_values=*/this->values_.size(),
757 /*null_count=*/0);
758 auto encoded_stats1 = statistics1->Encode();
759 EXPECT_TRUE(statistics1->HasNullCount());
760 EXPECT_EQ(0, statistics1->null_count());
761 EXPECT_TRUE(statistics1->Encode().has_null_count);
762 }
763 // Merge with null-count should also have null count
764 VerifyMergedStatistics(*statistics1, *statistics1,
765 [](TypedStatistics<TestType>* merged_statistics) {
766 EXPECT_TRUE(merged_statistics->HasNullCount());
767 EXPECT_EQ(0, merged_statistics->null_count());
768 auto encoded = merged_statistics->Encode();
769 EXPECT_TRUE(encoded.has_null_count);
770 EXPECT_EQ(0, encoded.null_count);
771 });
772
773 // When loaded from thrift, might not have null count.
774 std::shared_ptr<TypedStatistics<TestType>> statistics2;
775 {
776 EncodedStatistics encoded_statistics2;
777 encoded_statistics2.has_null_count = false;
778 statistics2 = std::dynamic_pointer_cast<TypedStatistics<TestType>>(
779 Statistics::Make(this->schema_.Column(0), &encoded_statistics2,
780 /*num_values=*/1000));
781 EXPECT_FALSE(statistics2->Encode().has_null_count);
782 EXPECT_FALSE(statistics2->HasNullCount());
783 }
784
785 // Merge without null-count should not have null count
786 VerifyMergedStatistics(*statistics1, *statistics2,
787 [](TypedStatistics<TestType>* merged_statistics) {
788 EXPECT_FALSE(merged_statistics->HasNullCount());
789 EXPECT_FALSE(merged_statistics->Encode().has_null_count);
790 });
791 }
792
793 // statistics.all_null_value is used to build the page index.
794 // If statistics doesn't have null count, all_null_value should be false.

Callers 1

TYPED_TESTFunction · 0.80

Calls 8

HasNullCountMethod · 0.80
MakeFunction · 0.70
GenerateDataMethod · 0.45
ColumnMethod · 0.45
UpdateMethod · 0.45
sizeMethod · 0.45
EncodeMethod · 0.45
null_countMethod · 0.45

Tested by

no test coverage detected