Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions datafusion/core/tests/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use arrow::{
};
use arrow_array::Float32Array;
use arrow_schema::ArrowError;
use datafusion_functions_aggregate::count::count_udaf;
use datafusion_functions_aggregate::count::{count_star, count_udaf};
use object_store::local::LocalFileSystem;
use std::fs;
use std::sync::Arc;
Expand Down Expand Up @@ -211,7 +211,6 @@ async fn test_count_wildcard_on_aggregate() -> Result<()> {
let sql_results = ctx
.sql("select count(*) from t1")
.await?
.select(vec![col("count(*)")])?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem correct to me, but I'm not pretty sure 🤔

.explain(false, false)?
.collect()
.await?;
Expand All @@ -220,8 +219,8 @@ async fn test_count_wildcard_on_aggregate() -> Result<()> {
let df_results = ctx
.table("t1")
.await?
.aggregate(vec![], vec![count(wildcard())])?
.select(vec![count(wildcard())])?
.aggregate(vec![], vec![count_star()])?
.select(vec![count_star()])?
.explain(false, false)?
.collect()
.await?;
Expand Down
46 changes: 38 additions & 8 deletions datafusion/functions-aggregate/src/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use datafusion_expr::{
function::AccumulatorArgs, utils::format_state_name, Accumulator, AggregateUDFImpl,
EmitTo, GroupsAccumulator, Signature, Volatility,
};
use datafusion_expr::{Expr, ReversedUDAF};
use datafusion_expr::{cast, lit, Expr, ReversedUDAF};
use datafusion_physical_expr_common::aggregate::groups_accumulator::accumulate::accumulate_indices;
use datafusion_physical_expr_common::{
aggregate::count_distinct::{
Expand All @@ -54,13 +54,43 @@ use datafusion_physical_expr_common::{
binary_map::OutputType,
};

make_udaf_expr_and_func!(
Count,
count,
expr,
"Count the number of non-null values in the column",
count_udaf
);
// make_udaf_expr_and_func!(
// Count,
// count,
// expr,
// "Count the number of non-null values in the column",
// count_udaf
// );
create_func!(Count, count_udaf);

pub fn count_star() -> Expr {
Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
count_udaf(),
// vec![lit(1)], // ideal args, but we need to change the displayed_name
vec![cast(lit(1), DataType::Int64).alias("*")], // to pass the test
false,
None,
None,
None,
))
}

pub fn count(expr: Expr) -> Expr {
// let expr = if let Expr::Wildcard { qualifier } = expr {
// cast(lit(1), DataType::Int64).alias("*")
// } else {
// expr
// };

Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
count_udaf(),
vec![expr],
false,
None,
None,
None,
))
}

pub fn count_distinct(expr: Expr) -> Expr {
Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
Expand Down