alamb commented on code in PR #14927: URL: https://github.com/apache/datafusion/pull/14927#discussion_r1978256452
########## 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: I don't really understand what this function is for. It seems pretty confusing Maye we could add a doc example or something to make it less confusing? Likewise for the `count_all_window_column` function ########## datafusion/sqllogictest/test_files/subquery.slt: ########## @@ -1393,3 +1393,37 @@ item1 1970-01-01T00:00:03 75 statement ok drop table source_table; + +# test count wildcard +statement count 0 +create table t1(a int) as values (1); + +statement count 0 +create table t2(b int) as values (1); + +query I +SELECT a FROM t1 WHERE EXISTS (SELECT count(*) FROM t2) +---- +1 + +query TT +explain SELECT a FROM t1 WHERE EXISTS (SELECT count(*) FROM t2) +---- +logical_plan +01)LeftSemi Join: +02)--TableScan: t1 projection=[a] +03)--SubqueryAlias: __correlated_sq_1 +04)----Projection: +05)------Aggregate: groupBy=[[]], aggr=[[count(Int64(1))]] +06)--------TableScan: t2 projection=[] Review Comment: weird -- 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