Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 8 additions & 1 deletion datafusion/src/physical_plan/aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ pub fn create_aggregate_expr(
name: String,
) -> Result<Arc<dyn AggregateExpr>> {
// coerce
let arg = coerce(args, input_schema, &signature(fun))?[0].clone();
let arg = coerce(args, input_schema, &signature(fun))?;
if arg.is_empty() {
return Err(DataFusionError::Plan(format!(
"Invalid or wrong number of arguments passed to aggregate: '{}'",
name,
)));
}
let arg = arg[0].clone();

let arg_types = args
.iter()
Expand Down
11 changes: 11 additions & 0 deletions datafusion/tests/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3437,3 +3437,14 @@ async fn test_physical_plan_display_indent_multi_children() {
expected, actual
);
}

#[tokio::test]
async fn test_aggregation_with_bad_arguments() -> Result<()> {
let mut ctx = ExecutionContext::new();
register_aggregate_csv(&mut ctx)?;
let sql = "SELECT COUNT(DISTINCT) FROM aggregate_test_100";
let logical_plan = ctx.create_logical_plan(&sql)?;
let physical_plan = ctx.create_physical_plan(&logical_plan);
assert!(physical_plan.is_err());
Ok(())
Comment thread
jgoday marked this conversation as resolved.
Outdated
}