jhorstmann commented on code in PR #2258:
URL: https://github.com/apache/arrow-rs/pull/2258#discussion_r934472553


##########
arrow/src/compute/kernels/comparison.rs:
##########
@@ -296,6 +298,41 @@ pub fn like_utf8_scalar<OffsetSize: OffsetSizeTrait>(
     Ok(BooleanArray::from(data))
 }
 
+fn replace_like_wildcards(text: &str) -> Result<String> {
+    let text = escape(text);

Review Comment:
   There is the `regex_syntax::is_meta_character` function, which is used by 
`escape`, using that we could handle both regex and like pattern characters in 
one loop. I think that could simplify the logic quite a bit.
   
   Pseudocode, not yet handling that `next` could be `None`:
   
   ```rust
   let mut chars_iter = text.chars().peekable()
   for c in chars_iter {
       if c == '\\' {
           append('\\'); 
           append('\\'); 
           let next = chars_iter.peek();
           if next == '%' || next == '_' {
              chars_iter.next(); // consume next, like character does not need 
to be transformed
               append(next);
           }
       } else if regex_syntax::is_meta_character(c) {
           append('\\');
           append(c);
       } else if c == '%' {
           append(".*");
       } else if c == '_' {
           append(".");
       } else {
           append(c);
       }
   }
   ```



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

Reply via email to