eliaperantoni commented on code in PR #14710: URL: https://github.com/apache/datafusion/pull/14710#discussion_r1958161891
########## datafusion/functions-aggregate/src/sum.rs: ########## @@ -143,11 +166,19 @@ impl AggregateUDFImpl for Sum { dt if dt.is_signed_integer() => Ok(DataType::Int64), dt if dt.is_unsigned_integer() => Ok(DataType::UInt64), dt if dt.is_floating() => Ok(DataType::Float64), - _ => exec_err!("Sum not supported for {}", data_type), + _ => exec_err!("Sum not supported for {}", data_type).map_err(|err| { + let diagnostic = Diagnostic::new_error( + format!( + "Coercion only supports integer and floating point values" + ), + sum.spans().first(), + ); Review Comment: I don't think "Coercion only supports integer and floating point values" is a message that an end user of an application built on DataFusion can understand. Perhaps something like `'sum' only works on numeric values`? ########## datafusion/sql/tests/cases/diagnostic.rs: ########## @@ -274,3 +279,36 @@ fn test_ambiguous_column_suggestion() -> Result<()> { Ok(()) } + +#[test] +fn test_sum_coerce_type() -> Result<()> { + let mut sum = Sum::new(); + let span = Span::new(Location::new(1, 1), Location::new(2, 1)); + let span_for_test = span; + sum.spans_mut().add_span(span); + let datatype_vec = vec![DataType::Date64]; + let res = sum.coerce_types(&datatype_vec); + let err = res.expect_err("Expected an error, but got success"); Review Comment: Can you use the same setup as other tests in this file? e.g. `get_spans`, `run_query`, etc. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org