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

Method TestMergeNullCount

cpp/src/parquet/statistics_test.cc:816–858  ·  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

814 // have null_count. Merging statistics from such page will result in an
815 // invalid null_count as well.
816 void TestMergeNullCount() {
817 this->GenerateData(/*num_values=*/1000);
818
819 // Page should have null-count even if no nulls
820 std::shared_ptr<TypedStatistics<TestType>> statistics1;
821 {
822 statistics1 = MakeStatistics<TestType>(this->schema_.Column(0));
823 statistics1->Update(this->values_ptr_, /*num_values=*/this->values_.size(),
824 /*null_count=*/0);
825 auto encoded_stats1 = statistics1->Encode();
826 EXPECT_TRUE(statistics1->HasNullCount());
827 EXPECT_EQ(0, statistics1->null_count());
828 EXPECT_TRUE(statistics1->Encode().has_null_count);
829 }
830 // Merge with null-count should also have null count
831 VerifyMergedStatistics(*statistics1, *statistics1,
832 [](TypedStatistics<TestType>* merged_statistics) {
833 EXPECT_TRUE(merged_statistics->HasNullCount());
834 EXPECT_EQ(0, merged_statistics->null_count());
835 auto encoded = merged_statistics->Encode();
836 EXPECT_TRUE(encoded.has_null_count);
837 EXPECT_EQ(0, encoded.null_count);
838 });
839
840 // When loaded from thrift, might not have null count.
841 std::shared_ptr<TypedStatistics<TestType>> statistics2;
842 {
843 EncodedStatistics encoded_statistics2;
844 encoded_statistics2.has_null_count = false;
845 statistics2 = std::dynamic_pointer_cast<TypedStatistics<TestType>>(
846 Statistics::Make(this->schema_.Column(0), &encoded_statistics2,
847 /*num_values=*/1000));
848 EXPECT_FALSE(statistics2->Encode().has_null_count);
849 EXPECT_FALSE(statistics2->HasNullCount());
850 }
851
852 // Merge without null-count should not have null count
853 VerifyMergedStatistics(*statistics1, *statistics2,
854 [](TypedStatistics<TestType>* merged_statistics) {
855 EXPECT_FALSE(merged_statistics->HasNullCount());
856 EXPECT_FALSE(merged_statistics->Encode().has_null_count);
857 });
858 }
859
860 // statistics.all_null_value is used to build the page index.
861 // 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