wangrunji0408 commented on issue #11413:
URL: https://github.com/apache/datafusion/issues/11413#issuecomment-2242629113

   > > An example would be
   > 
   > FWIW this implementation of concat would likely perform pretty poorly 
compared to a hand written one as it will both create and allocate a new 
temporary `String` for each row (and then presumably copy that value into a 
final StringArray/LargeStringArray).
   > 
   > ```rust
   > // declare concat
   > #[function("concat(string, string) -> string")]
   > #[function("concat(largestring, largestring) -> largestring")]
   > fn concat(lhs: &str, rhs: &str) -> String {
   >     format!("{}{}", lhs, rhs)
   > }
   > ```
   
   In this case, a writer-style return value is supported to avoid the overhead.
   
   ```rust
   #[function("concat(string, string) -> string")]
   #[function("concat(largestring, largestring) -> largestring")] // will be 
supported soon
   fn concat(lhs: &str, rhs: &str, output: &mut impl std::fmt::Write) {
       write!(output, "{}{}", lhs, rhs).unwrap();
   }
   ```
   
   The same technique can be applied to `binary` and `largebinary`. However, it 
is not yet implemented due to the lack of `impl std::io::Write for 
(Large)BinaryBuilder` in arrow crate.
   
   ```rust
   #[function("concat(binary, binary) -> binary")]
   #[function("concat(largebinary, largebinary) -> largebinary")]
   fn concat(lhs: &[u8], rhs: &[u8], output: &mut impl std::io::Write) {
       output.write_all(lhs).unwrap();
       output.write_all(rhs).unwrap();
   }
   ```


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

Reply via email to