Expr. simplification / rewrite: regex `.*foo.*`
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Is your feature request related to a problem or challenge?
SQL is a complex beast and sometimes users don't use the best tool for the job. A good example is:
```SQL
SELECT *
FROM t
WHERE c ~ '.*foo.*';
```
This regex will even get pushed down to the Parquet file filtering. However it effectively only means "`c` contains `'foo'`".
### Describe the solution you'd like
Extend the [regex simplification](https://github.com/apache/datafusion/blob/a026e7da2fe88f1923770ec3249c5f0e7b2ea6b0/datafusion/optimizer/src/simplify_expressions/regex.rs) and the [respective tests](https://github.com/apache/datafusion/blob/a026e7da2fe88f1923770ec3249c5f0e7b2ea6b0/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs#L3304-L3305) to rewrite `.*needle.*` to [`contains`](https://datafusion.apache.org/user-guide/sql/scalar_functions.html#contains).
### Describe alternatives you've considered
We could also rewrite this to `%foo%` (i.e. a `LIKE` statement)
### Additional context
\-
Contributor guide
Research direction
Start with datafusion/optimizer/src/simplify_expressions/regex.rs and the related tests in datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs around lines 3304-3305. Run the existing expression simplifier tests, then verify that the regex form `.*needle.*` is rewritten to `contains` and that the new behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100