jackwener commented on code in PR #6487:
URL: https://github.com/apache/arrow-datafusion/pull/6487#discussion_r1212710451


##########
datafusion/optimizer/src/simplify_expressions/regex.rs:
##########
@@ -166,6 +165,40 @@ fn is_anchored_literal(v: &[Hir]) -> bool {
         .all(|h| matches!(h.kind(), HirKind::Literal(_)))
 }
 
+/// returns true if the elements in a `Concat` pattern are:
+/// - `[Look::Start, Capture(Alternation(Literals...)), Look::End]`
+fn is_anchored_capture(v: &[Hir]) -> bool {
+    if 3 != v.len() {
+        return false;
+    }
+
+    let first_last = (
+        v.first().expect("length checked"),
+        v.last().expect("length checked"),
+    );
+    if !matches!(first_last,
+    (s, e) if s.kind() == &HirKind::Look(Look::Start)
+        && e.kind() == &HirKind::Look(Look::End)
+         )
+    {
+        return false;
+    }

Review Comment:
   ```suggestion
       if v.len() != 3
           || !matches!((v.first().unwrap().kind(), v.last().unwrap().kind()),
                    (&HirKind::Look(Look::Start), &HirKind::Look(Look::End)))
       {
           return false;
       }
   ```



-- 
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...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to