Dandandan commented on a change in pull request #9654:
URL: https://github.com/apache/arrow/pull/9654#discussion_r589762124
##########
File path: rust/datafusion/src/physical_plan/string_expressions.rs
##########
@@ -621,139 +463,28 @@ pub fn repeat<T: StringOffsetSizeTrait>(args:
&[ArrayRef]) -> Result<ArrayRef> {
Ok(Arc::new(result) as ArrayRef)
}
-/// Reverses the order of the characters in the string.
-/// reverse('abcde') = 'edcba'
-pub fn reverse<T: StringOffsetSizeTrait>(args: &[ArrayRef]) ->
Result<ArrayRef> {
+/// Replaces all occurrences in string of substring from with substring to.
+/// replace('abcdefabcdef', 'cd', 'XX') = 'abXXefabXXef'
+pub fn replace<T: StringOffsetSizeTrait>(args: &[ArrayRef]) ->
Result<ArrayRef> {
let string_array = downcast_string_arg!(args[0], "string", T);
+ let from_array = downcast_string_arg!(args[1], "from", T);
+ let to_array = downcast_string_arg!(args[2], "to", T);
let result = string_array
.iter()
- .map(|string| {
- string.map(|string: &str|
string.graphemes(true).rev().collect::<String>())
+ .zip(from_array.iter())
+ .zip(to_array.iter())
+ .map(|((string, from), to)| match (string, from, to) {
+ (None, _, _) => None,
Review comment:
Those cases can be converted to one wildcard case below
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]