lyne7-sc commented on code in PR #19547:
URL: https://github.com/apache/datafusion/pull/19547#discussion_r2668256445
##########
datafusion/functions/src/string/concat_ws.rs:
##########
@@ -136,43 +136,22 @@ impl ScalarUDFImpl for ConcatWsFunc {
None => return internal_err!("Expected string literal, got
{scalar:?}"),
};
- let mut result = String::new();
- // iterator over Option<str>
- let iter = &mut args[1..].iter().map(|arg| {
+ let mut values = Vec::with_capacity(args.len() - 1);
+ for arg in &args[1..] {
let ColumnarValue::Scalar(scalar) = arg else {
// loop above checks for all args being scalar
unreachable!()
};
- scalar.try_as_str()
- });
-
- // append first non null arg
- for scalar in iter.by_ref() {
- match scalar {
- Some(Some(s)) => {
- result.push_str(s);
- break;
- }
- Some(None) => {} // null literal string
- None => {
- return internal_err!("Expected string literal, got
{scalar:?}");
- }
- }
- }
- // handle subsequent non null args
- for scalar in iter.by_ref() {
- match scalar {
- Some(Some(s)) => {
- result.push_str(sep);
- result.push_str(s);
- }
+ match scalar.try_as_str() {
+ Some(Some(v)) => values.push(v),
Review Comment:
Based on local benchmark, the difference between the two is negligible. In
general, `join` even tends to be slightly faster.
This may be because `push sep` method introduces additional branching
operations.
Since there is no performance gain, perhaps sticking with `join` would be
better for readability?
--
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]