You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2021/06/08 21:32:26 UTC
[arrow-datafusion] branch master updated: Wrong aggregation
arguments error. (#505)
This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new 8495f95 Wrong aggregation arguments error. (#505)
8495f95 is described below
commit 8495f95d7b510109c70cf2b4b606ba020bffd27a
Author: Javier Goday <jg...@gmail.com>
AuthorDate: Tue Jun 8 23:32:19 2021 +0200
Wrong aggregation arguments error. (#505)
* 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 <an...@nerdnetworks.org>
* Fix test_aggregation_with_bad_arguments
Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
---
datafusion/src/physical_plan/aggregates.rs | 9 ++++++++-
datafusion/tests/sql.rs | 12 ++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/datafusion/src/physical_plan/aggregates.rs b/datafusion/src/physical_plan/aggregates.rs
index 3607f29..60025a3 100644
--- a/datafusion/src/physical_plan/aggregates.rs
+++ b/datafusion/src/physical_plan/aggregates.rs
@@ -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()
diff --git a/datafusion/tests/sql.rs b/datafusion/tests/sql.rs
index d77671e..5ce1884 100644
--- a/datafusion/tests/sql.rs
+++ b/datafusion/tests/sql.rs
@@ -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(())
+}