Skip to content

Commit

Permalink
Wrong aggregation arguments error. (#505)
Browse files Browse the repository at this point in the history
* Fix aggregate fn with invalid column

* Fix error message

* Fix error message

* fix clippy

* fix message and test

* avoid unwrap in test_aggregation_with_bad_arguments

* Update datafusion/tests/sql.rs

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* Fix test_aggregation_with_bad_arguments

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
  • Loading branch information
jgoday and alamb authored Jun 8, 2021
1 parent e39f311 commit 8495f95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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
12 changes: 12 additions & 0 deletions datafusion/tests/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3437,3 +3437,15 @@ 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);
let err = physical_plan.unwrap_err();
assert_eq!(err.to_string(), "Error during planning: Invalid or wrong number of arguments passed to aggregate: 'COUNT(DISTINCT )'");
Ok(())
}

0 comments on commit 8495f95

Please sign in to comment.