You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Rachelint (via GitHub)" <gi...@apache.org> on 2024/07/04 08:18:32 UTC

[PR] Impl a general get results from stats [datafusion]

Rachelint opened a new pull request, #11261:
URL: https://github.com/apache/datafusion/pull/11261

   ## Which issue does this PR close?
   Close #11153 
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "edmondop (via GitHub)" <gi...@apache.org>.
edmondop commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2211541999

   The draft implementation seems reasonable and all checks are passing 🎉  


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2211137678

   Thank you @Rachelint ❤️ 
   
    > It is mainly due to AggregateUDFImpl is defined in expr crate, and the needed PhysicalExpr is defined in datafusion-physical-expr-common crate which will refer exps a dependency. And if we import PhysicalExpr in expr, that will lead to cyclic dependecies...
   
   This makes sense -- I agree the ` AggregateUDFImpl` API should not be in terms of `PhysicalExpr` (for the dependency reasons you describe)
   
   One way I could think to get around this would be to figure out the column statistics in the physical planner and pass it directly (rather than making the UDF figure them out). Something like
   
   ```rust
   pub trait AggregateUDFImpl {
   ...
      /// If the output of this aggregate function can be determined 
      /// only from input statistics (e.g. COUNT(..) with 0 rows, is always 0)
      /// return that value
      ///
      /// # Arguments
      /// stats: Overall statistics for the input (including row count)
      /// arg_stats: Statistics, if known, for each input argument
       fn output_from_stats(
           &self,
           stats: &Statistics,
           arg_stats: &[Option<&ColumnStatistics>]
       ) -> Option<ScalarValue> {
           None
       }
   ...
   }
   ```
   
   ANother option might be to use the narrower API described on https://github.com/apache/datafusion/issues/11153
   
   ```rust
   impl AggregateExpr {
   
    /// Return the value of the aggregate function, if known, given the number of input rows.
    /// 
    /// Return None if the value can not be determined solely from the input.
    /// 
    /// # Examples
    /// * The `COUNT` aggregate would return `Some(11)` given `num_rows = 11`
    /// * The `MIN` aggregate would return `Some(Null)` given `num_rows = 0
    /// * The `MIN` aggregate would return `None` given num_rows = 11
    fn output_from_rows(&self, num_rows: usize) -> Option<ScalarValue> { None }
   ...
   }
   ```
   
   Though I think your idea is better (pass in statistics in generla)


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2220163407

   > Ok, been a bit busy the past couple of days, continue to read the related codes and think a relatively good way to solve this today... One simple way I could think to solve it temporarily for not blocking the progress of #10943 is that we just treat it a special case like `count`:
   > 
   > https://github.com/apache/datafusion/blob/1e0c06e14ae821ac6aa344f8acb638431a898ae8/datafusion/core/src/physical_optimizer/aggregate_statistics.rs#L144
   
   no worries -- there is a lot going on these days.
   
   I think your short term workaround sounds very clever to me 👍  I think it is fine to leave figuring out the right general API to add to AggregateUdfImpl as a future project (my rationale being that special casing "max" / "min" is no worse than hard coding the `Min` and `Max` types, and unblocks the conversion to AggregateUDF)


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "Rachelint (via GitHub)" <gi...@apache.org>.
Rachelint commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2221773014

   > > 😄 Thanks, I just impl the short term workaround now. But still worry about using the function name only to identify the built-in `min/max/count` in the optimizer. Assume that user define a udaf with a same name to overwrite the built-in (seems we can do it?). And the logic in user's `min/max/count` is totally different with the built-in. However the optimizer is unable to know the `min/max/count` is not the built-in(optimizer just identify by name), and do the mistaken optmization in result.
   > 
   > I agree -- it will not be correct. I think that is why we eventually need to move the logic out of the optimizer and into the AggregateUDFImpl itself.
   
   🤔 Seems indeed necessary to do that... 
   😄 Have finished the short term solution here.
   I originally want to avoid `downcast_ref::<AggregateFunctionExpr>()`, but found if we do that, we should add two functions `is_distinct` and `function_name` to `AggregateExpr` before. I am not sure if it is ok to add them... so I just impl with `downcast_ref::<AggregateFunctionExpr>()` now...


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "Rachelint (via GitHub)" <gi...@apache.org>.
Rachelint commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2219043216

   > > @alamb One thing I worry about the narrow api is that, it seems can't be used to support the original optimization of min/max?
   > > Maybe I misunderstand about it?
   > 
   > No, sorry, you are correct, I was mistaken
   
   Ok... Been a bit busy the past couple of days, continue to read the related codes and think a relative good way to solve this today...
   One way I could think to solve it temporarily for not blocking the progress of #10943 
   is that we just treat it a special case like `count`:
   https://github.com/apache/datafusion/blob/1e0c06e14ae821ac6aa344f8acb638431a898ae8/datafusion/core/src/physical_optimizer/aggregate_statistics.rs#L144
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Short term way to make `AggregateStatistics` still work when min/max is converted to udaf [datafusion]

Posted by "edmondop (via GitHub)" <gi...@apache.org>.
edmondop commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2227393151

   Thank you @Rachelint . I think I can resume https://github.com/apache/datafusion/pull/11013 unless @alamb you think there is more work we want to externalize/handle via separate PRs


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Short term way to make `AggregateStatistics` still work when min/max is converted to udaf [datafusion]

Posted by "edmondop (via GitHub)" <gi...@apache.org>.
edmondop commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2228774484

   Right ! It is looking good. The refactoring has broken an optimiser, will need to investigate


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "Rachelint (via GitHub)" <gi...@apache.org>.
Rachelint commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2211608009

   > Thank you @Rachelint ❤️
   > 
   > > It is mainly due to AggregateUDFImpl is defined in expr crate, and the needed PhysicalExpr is defined in datafusion-physical-expr-common crate which will refer exps a dependency. And if we import PhysicalExpr in expr, that will lead to cyclic dependecies...
   > 
   > This makes sense -- I agree the ` AggregateUDFImpl` API should not be in terms of `PhysicalExpr` (for the dependency reasons you describe)
   > 
   > One way I could think to get around this would be to figure out the column statistics in the physical planner and pass it directly (rather than making the UDF figure them out). Something like
   > 
   > ```rust
   > pub trait AggregateUDFImpl {
   > ...
   >    /// If the output of this aggregate function can be determined 
   >    /// only from input statistics (e.g. COUNT(..) with 0 rows, is always 0)
   >    /// return that value
   >    ///
   >    /// # Arguments
   >    /// stats: Overall statistics for the input (including row count)
   >    /// arg_stats: Statistics, if known, for each input argument
   >     fn output_from_stats(
   >         &self,
   >         stats: &Statistics,
   >         arg_stats: &[Option<&ColumnStatistics>]
   >     ) -> Option<ScalarValue> {
   >         None
   >     }
   > ...
   > }
   > ```
   > 
   > ANother option might be to use the narrower API described on #11153
   > 
   > ```rust
   > impl AggregateExpr {
   > 
   >  /// Return the value of the aggregate function, if known, given the number of input rows.
   >  /// 
   >  /// Return None if the value can not be determined solely from the input.
   >  /// 
   >  /// # Examples
   >  /// * The `COUNT` aggregate would return `Some(11)` given `num_rows = 11`
   >  /// * The `MIN` aggregate would return `Some(Null)` given `num_rows = 0
   >  /// * The `MIN` aggregate would return `None` given num_rows = 11
   >  fn output_from_rows(&self, num_rows: usize) -> Option<ScalarValue> { None }
   > ...
   > }
   > ```
   > 
   > Though I think your idea is better (pass in statistics in generla)
   
   
   
   > Thank you @Rachelint ❤️
   > 
   > > It is mainly due to AggregateUDFImpl is defined in expr crate, and the needed PhysicalExpr is defined in datafusion-physical-expr-common crate which will refer exps a dependency. And if we import PhysicalExpr in expr, that will lead to cyclic dependecies...
   > 
   > This makes sense -- I agree the ` AggregateUDFImpl` API should not be in terms of `PhysicalExpr` (for the dependency reasons you describe)
   > 
   > One way I could think to get around this would be to figure out the column statistics in the physical planner and pass it directly (rather than making the UDF figure them out). Something like
   > 
   > ```rust
   > pub trait AggregateUDFImpl {
   > ...
   >    /// If the output of this aggregate function can be determined 
   >    /// only from input statistics (e.g. COUNT(..) with 0 rows, is always 0)
   >    /// return that value
   >    ///
   >    /// # Arguments
   >    /// stats: Overall statistics for the input (including row count)
   >    /// arg_stats: Statistics, if known, for each input argument
   >     fn output_from_stats(
   >         &self,
   >         stats: &Statistics,
   >         arg_stats: &[Option<&ColumnStatistics>]
   >     ) -> Option<ScalarValue> {
   >         None
   >     }
   > ...
   > }
   > ```
   > 
   > ANother option might be to use the narrower API described on #11153
   > 
   > ```rust
   > impl AggregateExpr {
   > 
   >  /// Return the value of the aggregate function, if known, given the number of input rows.
   >  /// 
   >  /// Return None if the value can not be determined solely from the input.
   >  /// 
   >  /// # Examples
   >  /// * The `COUNT` aggregate would return `Some(11)` given `num_rows = 11`
   >  /// * The `MIN` aggregate would return `Some(Null)` given `num_rows = 0
   >  /// * The `MIN` aggregate would return `None` given num_rows = 11
   >  fn output_from_rows(&self, num_rows: usize) -> Option<ScalarValue> { None }
   > ...
   > }
   > ```
   > 
   > Though I think your idea is better (pass in statistics in generla)
   
   One thing I worry about the narrow api is that, it seems can't be used to support the origin optimization of min/max?
   https://github.com/apache/datafusion/blob/7df000a333a7d4018e1446ef900f652288b1f104/datafusion/core/src/physical_optimizer/aggregate_statistics.rs#L195-L221
   
   Maybe I misunderstand about it?
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "Rachelint (via GitHub)" <gi...@apache.org>.
Rachelint commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2220576084

   > > Ok, been a bit busy the past couple of days, continue to read the related codes and think a relatively good way to solve this today... One simple way I could think to solve it temporarily for not blocking the progress of #10943 is that we just treat it a special case like `count`:
   > > https://github.com/apache/datafusion/blob/1e0c06e14ae821ac6aa344f8acb638431a898ae8/datafusion/core/src/physical_optimizer/aggregate_statistics.rs#L144
   > 
   > no worries -- there is a lot going on these days.
   > 
   > I think your short term workaround sounds very clever to me 👍 I think it is fine to leave figuring out the right general API to add to AggregateUdfImpl as a future project (my rationale being that special casing "max" / "min" is no worse than hard coding the `Min` and `Max` types, and unblocks the conversion to AggregateUDF)
   
    :smile: Thanks, I just impl the short term workaround now.
   But still worry about using the function name only to Identify the built-in `min/max/count` in the optimizer.
   Assume that user define a to udf with a same name to overwrite the built-ins (seems we can do it?).
   And the logic in user's `min/max/count` is totally different with the built-in. 
   However the optimizer is unable to know the `min/max/count` is not the built-in(optimizer just identify by name), and do the mistaken optmization in result. 


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Short term way to make `AggregateStatistics` still work when min/max is converted to udaf [datafusion]

Posted by "Rachelint (via GitHub)" <gi...@apache.org>.
Rachelint commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2225678848

   Thanks @alamb for review, will continue to try to move them into `AggregateUDFImpl`, and comments have been added.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "Rachelint (via GitHub)" <gi...@apache.org>.
Rachelint commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2208428281

   @alamb @EduardoVega 
   I have made draf impl...
   I define a new function `output_from_stats` as a general function to get results directly from stats if possible.
   Howerver, when I impl adapt it to `AggregateUDFImpl`, I found I can't get the physical exprs which is needed, see the original code in physical optimizer:
   https://github.com/apache/datafusion/blob/569be9eb1ba60d3e842f22de5080c732ac2206f4/datafusion/core/src/physical_optimizer/aggregate_statistics.rs#L250-L257
   
   It is mainly due to `AggregateUDFImpl` is defined in `expr` crate, and the needed `PhysicalExpr` is defined in `datafusion-physical-expr-common` crate which will refer `exps` a dependency. And if we import `PhysicalExpr` in `expr`, that will lead to cyclic dependecies...
   
   For solving it, I define a `AggregateArgExprs` trait in `expr` crate, and impl it for the `Vec<Arc<dyn PhysicalExpr>>`. It can work but we need to downcast it to `&[Arc<dyn PhysicalExpr>]` when using it in `output_from_stats` of the `udaf`(see the impl of `count`...). I am not sure if it is a good way to impl like this...


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Short term way to make `AggregateStatistics` still work when min/max is converted to udaf [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #11261:
URL: https://github.com/apache/datafusion/pull/11261


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2221269975

   > 😄 Thanks, I just impl the short term workaround now. But still worry about using the function name only to identify the built-in `min/max/count` in the optimizer. Assume that user define a udaf with a same name to overwrite the built-in (seems we can do it?). And the logic in user's `min/max/count` is totally different with the built-in. However the optimizer is unable to know the `min/max/count` is not the built-in(optimizer just identify by name), and do the mistaken optmization in result.
   
   I agree -- it will not be correct. I think that is why we eventually need to move the logic out of the optimizer and into the AggregateUDFImpl itself. 


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Impl a general get results from stats [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2212541638

   > @alamb One thing I worry about the narrow api is that, it seems can't be used to support the original optimization of min/max?
   > 
   > Maybe I misunderstand about it?
   
   No, sorry, you are correct, I was mistaken
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Short term way to make `AggregateStatistics` still work when min/max is converted to udaf [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#discussion_r1675789494


##########
datafusion/core/src/physical_optimizer/aggregate_statistics.rs:
##########
@@ -273,6 +263,44 @@ fn take_optimizable_max(
     None
 }
 
+fn is_non_distinct_count(agg_expr: &dyn AggregateExpr) -> bool {
+    if let Some(agg_expr) = agg_expr.as_any().downcast_ref::<AggregateFunctionExpr>() {
+        if agg_expr.fun().name() == "count" && !agg_expr.is_distinct() {
+            return true;
+        }
+    }
+
+    false
+}
+
+fn is_min(agg_expr: &dyn AggregateExpr) -> bool {

Review Comment:
   ```suggestion
   // TODO: Move this check into AggregateUDFImpl
   // https://github.com/apache/datafusion/issues/11153
   fn is_min(agg_expr: &dyn AggregateExpr) -> bool {
   ```



##########
datafusion/core/src/physical_optimizer/aggregate_statistics.rs:
##########
@@ -273,6 +263,44 @@ fn take_optimizable_max(
     None
 }
 
+fn is_non_distinct_count(agg_expr: &dyn AggregateExpr) -> bool {

Review Comment:
   I really like the encapsulation of this logic into functions 👍 
   
   ```suggestion
   // TODO: Move this check into AggregateUDFImpl
   // https://github.com/apache/datafusion/issues/11153
   fn is_non_distinct_count(agg_expr: &dyn AggregateExpr) -> bool {
   ```



##########
datafusion/core/src/physical_optimizer/aggregate_statistics.rs:
##########
@@ -273,6 +263,44 @@ fn take_optimizable_max(
     None
 }
 
+fn is_non_distinct_count(agg_expr: &dyn AggregateExpr) -> bool {
+    if let Some(agg_expr) = agg_expr.as_any().downcast_ref::<AggregateFunctionExpr>() {
+        if agg_expr.fun().name() == "count" && !agg_expr.is_distinct() {
+            return true;
+        }
+    }
+
+    false
+}
+
+fn is_min(agg_expr: &dyn AggregateExpr) -> bool {
+    if agg_expr.as_any().is::<expressions::Min>() {
+        return true;
+    }
+
+    if let Some(agg_expr) = agg_expr.as_any().downcast_ref::<AggregateFunctionExpr>() {
+        if agg_expr.fun().name() == "min" {
+            return true;
+        }
+    }
+
+    false
+}
+
+fn is_max(agg_expr: &dyn AggregateExpr) -> bool {

Review Comment:
   ```suggestion
   // TODO: Move this check into AggregateUDFImpl
   // https://github.com/apache/datafusion/issues/11153
   fn is_max(agg_expr: &dyn AggregateExpr) -> bool {
   ```



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Short term way to make `AggregateStatistics` still work when min/max is converted to udaf [datafusion]

Posted by "edmondop (via GitHub)" <gi...@apache.org>.
edmondop commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2228792230

   Makes sense. I am almost done on the other pr I need to understand why one optimisation was lost


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Short term way to make `AggregateStatistics` still work when min/max is converted to udaf [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #11261:
URL: https://github.com/apache/datafusion/pull/11261#issuecomment-2228755312

   > Thank you @Rachelint . I think I can resume #11013 unless @alamb you think there is more work we want to externalize/handle via separate PRs
   
   I am not sure -- I suggest going through all uses of `Min` and `Max` (specifically look for any `downcast_ref::<Min>` and `downcast_ref::<Max>` references and see if there are any other places that need to be removed
   
   The goal of https://github.com/apache/datafusion/pull/11013 I think should also remove the built in Min/Max values
   
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org