asolimando commented on code in PR #19957:
URL: https://github.com/apache/datafusion/pull/19957#discussion_r2722735298
##########
datafusion/common/src/stats.rs:
##########
@@ -632,7 +632,24 @@ impl Statistics {
col_stats.max_value =
col_stats.max_value.max(&item_col_stats.max_value);
col_stats.min_value =
col_stats.min_value.min(&item_col_stats.min_value);
col_stats.sum_value =
col_stats.sum_value.add(&item_col_stats.sum_value);
- col_stats.distinct_count = Precision::Absent;
+ // Use max as a conservative lower bound for distinct count
+ // (can't accurately merge NDV since duplicates may exist across
partitions)
+ col_stats.distinct_count =
+ match (&col_stats.distinct_count,
&item_col_stats.distinct_count) {
+ (Precision::Exact(a), Precision::Exact(b))
+ | (Precision::Inexact(a), Precision::Exact(b))
+ | (Precision::Exact(a), Precision::Inexact(b))
+ | (Precision::Inexact(a), Precision::Inexact(b)) => {
+ Precision::Inexact(if a >= b { *a } else { *b })
+ }
+ (Precision::Exact(v), Precision::Absent)
+ | (Precision::Inexact(v), Precision::Absent)
+ | (Precision::Absent, Precision::Exact(v))
+ | (Precision::Absent, Precision::Inexact(v)) => {
+ Precision::Inexact(*v)
+ }
+ (Precision::Absent, Precision::Absent) =>
Precision::Absent,
+ };
Review Comment:
Thanks a lot, this is very neat, addressed in
db182e50dc2b920e2da03380729b70cb4ec58c39!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]