jonathanc-n commented on code in PR #20845:
URL: https://github.com/apache/datafusion/pull/20845#discussion_r2913207876


##########
datafusion/core/tests/physical_optimizer/aggregate_statistics.rs:
##########
@@ -402,3 +409,142 @@ async fn utf8_grouping_min_max_limit_fallbacks() -> 
Result<()> {
 
     Ok(())
 }
+
+fn mock_data_with_distinct_count(

Review Comment:
   Are we able to combine these two functions



##########
datafusion/functions-aggregate/src/count.rs:
##########
@@ -365,31 +365,37 @@ impl AggregateUDFImpl for Count {
     }
 
     fn value_from_stats(&self, statistics_args: &StatisticsArgs) -> 
Option<ScalarValue> {
+        let [expr] = statistics_args.exprs else {
+            return None;
+        };
+        let col_stats = &statistics_args.statistics.column_statistics;
+
         if statistics_args.is_distinct {
+            // Only column references can be resolved from statistics;
+            // expressions like casts or literals are not supported.
+            let col_expr = 
expr.as_any().downcast_ref::<expressions::Column>()?;
+            if let Precision::Exact(dc) = 
col_stats[col_expr.index()].distinct_count {
+                return Some(ScalarValue::Int64(Some(dc as i64)));

Review Comment:
   Distinct count is usize, we should deal with the case where it could overflow



-- 
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]

Reply via email to