alamb commented on code in PR #6369:
URL: https://github.com/apache/arrow-datafusion/pull/6369#discussion_r1196977982
##########
datafusion/optimizer/src/simplify_expressions/regex.rs:
##########
@@ -130,6 +139,46 @@ fn is_safe_for_like(c: char) -> bool {
(c != '%') && (c != '_')
}
+/// returns true if the elements in a `Concat` pattern are:
+/// - `[Look::Start, Look::End]`
+/// - `[Look::Start, Literal(_), Look::End]`
+fn is_anchored_literal(v: &[Hir]) -> bool {
+ match v.len() {
+ 2..=3 => (),
+ _ => 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;
+ }
+
+ v.iter()
+ .skip(1)
+ .take(v.len() - 2)
+ .all(|h| matches!(h.kind(), HirKind::Literal(_)))
+}
+
+/// extracts a string literal expression assuming that [`is_anchored_literal`]
+/// returned true.
+fn anchored_literal_to_expr(v: &[Hir]) -> Option<Expr> {
+ match v.len() {
+ 2 => Some(lit("")),
+ 3 => {
+ let HirKind::Literal(l) = v[1].kind() else { return None };
+ str_from_literal(l).map(lit)
+ }
+ _ => None,
+ }
+}
+
fn lower_simple(mode: &OperatorMode, left: &Expr, hir: &Hir) -> Option<Expr> {
println!("Considering hir kind: mode {mode:?} hir: {hir:?}");
Review Comment:
I noticed this stray `println` while reviewing this code so I propose
removing it: https://github.com/apache/arrow-datafusion/pull/6375
--
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]