geoffreyclaude commented on code in PR #14412:
URL: https://github.com/apache/datafusion/pull/14412#discussion_r1962046382
##########
datafusion/functions-aggregate/src/string_agg.rs:
##########
@@ -106,20 +113,40 @@ impl AggregateUDFImpl for StringAgg {
Ok(DataType::LargeUtf8)
}
+ fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<Field>> {
+ self.array_agg.state_fields(args)
+ }
+
fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn
Accumulator>> {
- if let Some(lit) =
acc_args.exprs[1].as_any().downcast_ref::<Literal>() {
- return match lit.value().try_as_str() {
- Some(Some(delimiter)) => {
- Ok(Box::new(StringAggAccumulator::new(delimiter)))
- }
- Some(None) => Ok(Box::new(StringAggAccumulator::new(""))),
- None => {
- not_impl_err!("StringAgg not supported for delimiter {}",
lit.value())
- }
- };
- }
+ let Some(lit) = acc_args.exprs[1].as_any().downcast_ref::<Literal>()
else {
+ return not_impl_err!(
+ "The second argument of the string_agg function must be a
string literal"
+ );
+ };
+
+ let delimiter = if lit.value().is_null() {
+ // If the second argument (the delimiter that joins strings) is
NULL, join
+ // on an empty string. (e.g. [a, b, c] => "abc").
+ ""
+ } else if let Some(lit_string) = lit.value().try_as_str() {
+ lit_string.unwrap_or("")
+ } else {
+ return not_impl_err!(
+ "StringAgg not supported for delimiter {}",
Review Comment:
Could you just add brackets or quotes around the `{}`? So unprintable or
other weirdly formatted delimiters don't produce the error `"StringAgg not
supported for delimiter "`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]