findepi commented on code in PR #14689:
URL: https://github.com/apache/datafusion/pull/14689#discussion_r1957777054


##########
datafusion/functions-aggregate/src/planner.rs:
##########
@@ -0,0 +1,63 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! SQL planning extensions like [`AggregateFunctionPlanner`]
+
+use datafusion_common::Result;
+use datafusion_expr::{
+    expr::AggregateFunction,
+    lit,
+    planner::{ExprPlanner, PlannerResult, RawAggregateExpr},
+    utils::COUNT_STAR_EXPANSION,
+    Expr,
+};
+
+#[derive(Debug)]
+pub struct AggregateFunctionPlanner;
+
+impl ExprPlanner for AggregateFunctionPlanner {
+    fn plan_aggregate(
+        &self,
+        expr: RawAggregateExpr,
+    ) -> Result<PlannerResult<RawAggregateExpr>> {
+        if expr.func.name() == "count"
+            && (expr.args.len() == 1 && matches!(expr.args[0], Expr::Wildcard 
{ .. })

Review Comment:
   I hope we are able to remove `Expr::Wildcard` as a follow-up 🙏 



##########
datafusion/functions-aggregate/src/count.rs:
##########
@@ -79,6 +79,12 @@ pub fn count_distinct(expr: Expr) -> Expr {
     ))
 }
 
+/// Count(*), Count(), Count(1) are all equivalent expression
+/// In DataFusion, we convert them to Count(1) expression
+pub fn count_wildcard() -> Expr {

Review Comment:
   wildcard here is a syntactical remnant.
   
   this is a function to call all rows, so call it like that
   
   ```suggestion
   /// Creates aggregation to count all rows
   pub fn count_all() -> Expr {
   ```



##########
datafusion/core/src/execution/context/csv.rs:
##########
@@ -116,11 +116,11 @@ mod tests {
 
         assert_eq!(results.len(), 1);
         let expected = [
-            "+--------------+--------------+----------+",
-            "| sum(test.c1) | sum(test.c2) | count(*) |",
-            "+--------------+--------------+----------+",
-            "| 10           | 110          | 20       |",
-            "+--------------+--------------+----------+",
+            "+--------------+--------------+--------------+",
+            "| sum(test.c1) | sum(test.c2) | count_star() |",

Review Comment:
   > Yes we don't. count(const_expr), count(), count(*) are all the same thing, 
I don't think we need to preserve them all
   
   fine for me.
   
   calling it just `count()` (or `count(1)`) would be shorter and cleaner
   
   
   in particular, the `count_star` function should not exist as user-callable 
syntax, (`SELECT count_star()` should fail with "function not found")



-- 
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-unsubscr...@datafusion.apache.org

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


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

Reply via email to