viirya opened a new pull request, #24380:
URL: https://github.com/apache/datafusion/pull/24380
## Which issue does this PR close?
- Closes #24379.
## Rationale for this change
`simplify_regex_expr` rewrites `col ~ '.*'` to `col IS NOT NULL`. For a NULL
input that returns `false`, but `NULL ~ '.*'` is `NULL` under three-valued
logic — so the rewrite produces wrong results in a projection context:
```sql
SELECT s, s ~ '.*' FROM (VALUES (CAST(NULL AS VARCHAR)), ('x')) t(s);
-- NULL row currently returns `false`; it should be NULL
```
The `!~` (`RegexNotMatch`) branch of the same rule is already NULL-aware
(`col IS NULL AND NULL`); only the `~` branch dropped the NULL.
## What changes are included in this PR?
- Rewrite `col ~ '.*'` to `col IS NOT NULL OR NULL` — `true` for a non-NULL
string, `NULL` for a NULL input.
- In a WHERE filter both FALSE and NULL reject the row, so filter *results*
are unchanged; only the plan text and projection-context values differ.
Existing filter-plan expectations in `simplify_expr.slt` and the
`test_simplify_regex_special_cases` unit test are updated accordingly, and a
projection regression test is added.
## Are these changes tested?
Yes.
- New projection regression test in `simplify_expr.slt` asserting `col ~
'.*'` returns `true`/`true`/`NULL` for `'foo'`/`''`/`NULL`.
- Updated the two filter-context plan expectations (logical + physical) that
previously encoded the `IS NOT NULL` rewrite.
- `simplify_expr.slt`, the `regexp/*` SLTs, and the optimizer simplify unit
tests all pass.
## Are there any user-facing changes?
`col ~ '.*'` in a projection now returns `NULL` for a NULL input instead of
`false`, matching SQL semantics. No API changes.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]