Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3909,6 +3909,7 @@ class TestArrayDataStatistics : public ::testing::Test {
public:
void SetUp() {
valids_ = {1, 0, 1, 1};
row_count_ = static_cast<int64_t>(valids_.size());
null_count_ = std::count(valids_.begin(), valids_.end(), 0);
distinct_count_ = 3.0;
max_byte_width_ = 4.0;
Expand All @@ -3921,6 +3922,7 @@ class TestArrayDataStatistics : public ::testing::Test {
data_ = ArrayData::Make(int32(), values_.size(), {null_buffer_, values_buffer_},
null_count_);
data_->statistics = std::make_shared<ArrayStatistics>();
data_->statistics->row_count = row_count_;
data_->statistics->null_count = null_count_;
data_->statistics->distinct_count = distinct_count_;
data_->statistics->max_byte_width = max_byte_width_;
Expand All @@ -3934,6 +3936,7 @@ class TestArrayDataStatistics : public ::testing::Test {

protected:
std::vector<uint8_t> valids_;
int64_t row_count_;
int64_t null_count_;
double distinct_count_;
double max_byte_width_;
Expand All @@ -3950,6 +3953,9 @@ TEST_F(TestArrayDataStatistics, MoveConstructor) {
ArrayData copied_data(*data_);
ArrayData moved_data(std::move(copied_data));

ASSERT_TRUE(moved_data.statistics->row_count.has_value());
ASSERT_EQ(row_count_, std::get<int64_t>(moved_data.statistics->row_count.value()));

ASSERT_TRUE(moved_data.statistics->null_count.has_value());
ASSERT_EQ(null_count_, std::get<int64_t>(moved_data.statistics->null_count.value()));

Expand Down Expand Up @@ -3980,6 +3986,9 @@ TEST_F(TestArrayDataStatistics, MoveConstructor) {
TEST_F(TestArrayDataStatistics, CopyConstructor) {
ArrayData copied_data(*data_);

ASSERT_TRUE(copied_data.statistics->row_count.has_value());
ASSERT_EQ(row_count_, std::get<int64_t>(copied_data.statistics->row_count.value()));

ASSERT_TRUE(copied_data.statistics->null_count.has_value());
ASSERT_EQ(null_count_, std::get<int64_t>(copied_data.statistics->null_count.value()));

Expand Down Expand Up @@ -4012,6 +4021,9 @@ TEST_F(TestArrayDataStatistics, MoveAssignment) {
ArrayData moved_data;
moved_data = std::move(copied_data);

ASSERT_TRUE(moved_data.statistics->row_count.has_value());
ASSERT_EQ(row_count_, std::get<int64_t>(moved_data.statistics->row_count.value()));

ASSERT_TRUE(moved_data.statistics->null_count.has_value());
ASSERT_EQ(null_count_, std::get<int64_t>(moved_data.statistics->null_count.value()));

Expand Down Expand Up @@ -4043,6 +4055,9 @@ TEST_F(TestArrayDataStatistics, CopyAssignment) {
ArrayData copied_data;
copied_data = *data_;

ASSERT_TRUE(copied_data.statistics->row_count.has_value());
ASSERT_EQ(row_count_, std::get<int64_t>(copied_data.statistics->row_count.value()));

ASSERT_TRUE(copied_data.statistics->null_count.has_value());
ASSERT_EQ(null_count_, std::get<int64_t>(copied_data.statistics->null_count.value()));

Expand Down Expand Up @@ -4074,6 +4089,9 @@ TEST_F(TestArrayDataStatistics, CopyTo) {
ASSERT_OK_AND_ASSIGN(auto copied_data,
data_->CopyTo(arrow::default_cpu_memory_manager()));

ASSERT_TRUE(copied_data->statistics->row_count.has_value());
ASSERT_EQ(row_count_, std::get<int64_t>(copied_data->statistics->row_count.value()));

ASSERT_TRUE(copied_data->statistics->null_count.has_value());
ASSERT_EQ(null_count_, std::get<int64_t>(copied_data->statistics->null_count.value()));

Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/array/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ struct ARROW_EXPORT ArrayStatistics {
return std::visit(visitor, value.value());
}

/// \brief The number of rows, may not be set
/// Note: when set to `int64_t`, it represents `exact_row_count`,
/// and when set to `double`, it represents `approximate_row_count`.
/// Note: this value is not used by \ref arrow::RecordBatch::MakeStatisticsArray.
std::optional<CountType> row_count = std::nullopt;

/// \brief The number of null values, may not be set
/// Note: when set to `int64_t`, it represents `exact_null_count`,
/// and when set to `double`, it represents `approximate_null_count`.
Expand Down
28 changes: 28 additions & 0 deletions cpp/src/arrow/array/statistics_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@

namespace arrow {

TEST(TestArrayStatistics, RowCountExact) {
ArrayStatistics statistics;
ASSERT_FALSE(statistics.row_count.has_value());
statistics.row_count = 45;
ASSERT_TRUE(statistics.row_count.has_value());
ASSERT_EQ(45, std::get<int64_t>(statistics.row_count.value()));
}

TEST(TestArrayStatistics, RowCountApproximate) {
ArrayStatistics statistics;
ASSERT_FALSE(statistics.row_count.has_value());
statistics.row_count = 45.0;
ASSERT_TRUE(statistics.row_count.has_value());
ASSERT_DOUBLE_EQ(45.0, std::get<double>(statistics.row_count.value()));
}

TEST(TestArrayStatistics, NullCountExact) {
ArrayStatistics statistics;
ASSERT_FALSE(statistics.null_count.has_value());
Expand Down Expand Up @@ -114,6 +130,18 @@ TEST(TestArrayStatistics, Equals) {

ASSERT_EQ(statistics1, statistics2);

// Test ROW_COUNT_EXACT
statistics1.row_count = 45;
ASSERT_NE(statistics1, statistics2);
statistics2.row_count = 45;
ASSERT_EQ(statistics1, statistics2);

// Test ROW_COUNT_APPROXIMATE
statistics1.row_count = 45.0;
ASSERT_NE(statistics1, statistics2);
statistics2.row_count = 45.0;
ASSERT_EQ(statistics1, statistics2);

// Test NULL_COUNT_EXACT
statistics1.null_count = 29;
ASSERT_NE(statistics1, statistics2);
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/arrow/compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,9 @@ bool ArrayStatisticsOptionalValueEquals(const std::optional<Type>& left,

bool ArrayStatisticsEqualsImpl(const ArrayStatistics& left, const ArrayStatistics& right,
const EqualOptions& equal_options) {
return ArrayStatisticsOptionalValueEquals(left.null_count, right.null_count,
return ArrayStatisticsOptionalValueEquals(left.row_count, right.row_count,
equal_options) &&
ArrayStatisticsOptionalValueEquals(left.null_count, right.null_count,
equal_options) &&
ArrayStatisticsOptionalValueEquals(left.distinct_count, right.distinct_count,
equal_options) &&
Expand Down
Loading