alamb commented on code in PR #15299:
URL: https://github.com/apache/datafusion/pull/15299#discussion_r2004125741


##########
datafusion/optimizer/src/simplify_expressions/regex.rs:
##########
@@ -43,6 +47,23 @@ pub fn simplify_regex_expr(
     let mode = OperatorMode::new(&op);
 
     if let Expr::Literal(ScalarValue::Utf8(Some(pattern))) = right.as_ref() {
+        // Handle the special case for ".*" pattern
+        if pattern == ANY_CHAR_REGEX_PATTERN {
+            let new_expr = if mode.not {
+                // not empty
+                let empty_lit = Box::new(lit(""));
+                Expr::BinaryExpr(BinaryExpr {
+                    left,
+                    op: Operator::Eq,
+                    right: empty_lit,
+                })
+            } else {
+                // always true

Review Comment:
   I think this needs to handle nulls too as `null ~ '.*'` is not `true` (it is 
null)
   
   ```sql
   > create or replace table foo(x varchar) as values (1), (2), (null);
   0 row(s) fetched.
   Elapsed 0.004 seconds.
   
   > select x ~ '.*' from foo;
   +--------------------+
   | foo.x ~ Utf8(".*") |
   +--------------------+
   | true               |
   | true               |
   | NULL               |
   +--------------------+
   3 row(s) fetched.
   Elapsed 0.016 seconds.
   ```
   
   So maybe instead of `lit(true)` it is `x.is_not_null()` 🤔 



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