jayzhan211 commented on code in PR #14927:
URL: https://github.com/apache/datafusion/pull/14927#discussion_r1978403578


##########
datafusion/functions-aggregate/src/count.rs:
##########
@@ -80,8 +83,32 @@ pub fn count_distinct(expr: Expr) -> Expr {
 }
 
 /// Creates aggregation to count all rows, equivalent to `COUNT(*)`, 
`COUNT()`, `COUNT(1)`
+/// Alias to count(*) for backward comaptibility
 pub fn count_all() -> Expr {
-    count(Expr::Literal(COUNT_STAR_EXPANSION))
+    count(Expr::Literal(COUNT_STAR_EXPANSION)).alias("count(*)")
+}
+
+/// Creates window aggregation to count all rows, equivalent to `COUNT(*)`, 
`COUNT()`, `COUNT(1)`
+pub fn count_all_window() -> Expr {
+    Expr::WindowFunction(WindowFunction::new(
+        WindowFunctionDefinition::AggregateUDF(count_udaf()),
+        vec![Expr::Literal(COUNT_STAR_EXPANSION)],
+    ))
+}
+
+/// Create count wildcard window func of Expr::Column
+pub fn count_all_window_column() -> Expr {
+    col(Expr::WindowFunction(WindowFunction::new(
+        WindowFunctionDefinition::AggregateUDF(count_udaf()),
+        vec![Expr::Literal(COUNT_STAR_EXPANSION)],
+    ))
+    .schema_name()
+    .to_string())
+}
+
+/// Create count wildcard of Expr::Column

Review Comment:
   One of the example is been used in 
`test_count_wildcard_on_where_scalar_subquery`
   
   ```rust
    let df_results = ctx
           .table("t1")
           .await?
           .filter(
               scalar_subquery(Arc::new(
                   ctx.table("t2")
                       .await?
                       .filter(out_ref_col(DataType::UInt32, 
"t1.a").eq(col("t2.a")))?
                       .aggregate(vec![], vec![count_all()])?
                       .select(vec![count_all_column()])?
                       .into_unoptimized_plan(),
               ))
               .gt(lit(ScalarValue::UInt8(Some(0)))),
           )?
           .select(vec![col("t1.a"), col("t1.b")])?
           .explain(false, false)?
           .collect()
           .await?;
   ```



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