Skip to content
Merged
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
26 changes: 23 additions & 3 deletions datafusion/core/tests/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ use datafusion_execution::config::SessionConfig;
use datafusion_expr::expr::{GroupingSet, Sort};
use datafusion_expr::Expr::Wildcard;
use datafusion_expr::{
avg, col, count, exists, expr, in_subquery, lit, max, out_ref_col, scalar_subquery,
sum, AggregateFunction, Expr, ExprSchemable, WindowFrame, WindowFrameBound,
WindowFrameUnits, WindowFunction,
array_agg, avg, col, count, exists, expr, in_subquery, lit, max, out_ref_col,
scalar_subquery, sum, AggregateFunction, Expr, ExprSchemable, WindowFrame,
WindowFrameBound, WindowFrameUnits, WindowFunction,
};
use datafusion_physical_expr::var_provider::{VarProvider, VarType};

Expand Down Expand Up @@ -1340,3 +1340,23 @@ async fn use_var_provider() -> Result<()> {
dataframe.collect().await?;
Ok(())
}

#[tokio::test]
async fn test_array_agg() -> Result<()> {
let df = create_test_table("test")
.await?
.aggregate(vec![], vec![array_agg(col("a"))])?;

let results = df.collect().await?;

let expected = vec![
"+-------------------------------------+",
"| ARRAY_AGG(test.a) |",
"+-------------------------------------+",
"| [abcDEF, abc123, CBAdef, 123AbcDef] |",
"+-------------------------------------+",
];
assert_batches_eq!(expected, &results);

Ok(())
}
11 changes: 11 additions & 0 deletions datafusion/expr/src/expr_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ pub fn sum(expr: Expr) -> Expr {
))
}

/// Create an expression to represent the array_agg() aggregate function
pub fn array_agg(expr: Expr) -> Expr {
Expr::AggregateFunction(AggregateFunction::new(
aggregate_function::AggregateFunction::ArrayAgg,
vec![expr],
false,
None,
None,
))
}

/// Create an expression to represent the avg() aggregate function
pub fn avg(expr: Expr) -> Expr {
Expr::AggregateFunction(AggregateFunction::new(
Expand Down