theirix commented on code in PR #20787:
URL: https://github.com/apache/datafusion/pull/20787#discussion_r2970397129


##########
datafusion/functions/src/string/concat.rs:
##########
@@ -120,26 +122,35 @@ impl ScalarUDFImpl for ConcatFunc {
             }
         });
 
-        let array_len = args.iter().find_map(|x| match x {
-            ColumnarValue::Array(array) => Some(array.len()),
-            _ => None,
-        });
+        let array_len = args
+            .iter()
+            .filter_map(|x| match x {
+                ColumnarValue::Array(array) => Some(array.len()),
+                _ => None,
+            })
+            .next();
 
         // Scalar
         if array_len.is_none() {
-            let mut values = Vec::with_capacity(args.len());
+            let mut values: Vec<&str> = Vec::with_capacity(args.len());
             for arg in &args {
                 let ColumnarValue::Scalar(scalar) = arg else {
                     return internal_err!("concat expected scalar value, got 
{arg:?}");
                 };
-
-                match scalar.try_as_str() {
-                    Some(Some(v)) => values.push(v),
-                    Some(None) => {} // null literal
-                    None => plan_err!(
-                        "Concat function does not support scalar type {}",
-                        scalar
-                    )?,
+                if let ScalarValue::Binary(Some(value)) = scalar {
+                    let s: &str = std::str::from_utf8(value).map_err(|_| {
+                        exec_datafusion_err!("invalid UTF-8 in binary literal: 
{value:?}")
+                    })?;
+                    values.push(s);
+                } else {
+                    match scalar.try_as_str() {
+                        Some(Some(v)) => values.push(v),
+                        Some(None) => {} // null literal
+                        None => plan_err!(
+                            "Concat function does not support scalar type {}",
+                            scalar
+                        )?,
+                    }
                 }
             }
             let result = values.concat();

Review Comment:
   Code was changed since then. However, I extracted a small helper - not as 
elegant as expected, but it works fine.



-- 
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]

Reply via email to