adriangb opened a new pull request, #25352: URL: https://github.com/apache/datafusion/pull/25352
## Which issue does this PR close? - Part of https://github.com/apache/datafusion/issues/25351. This PR does not close it. ## Rationale for this change When a pattern does not compile, `regexp_count` and `regexp_instr` report only the pattern. The user does not learn why the pattern is invalid: ```sql CREATE TABLE t (s VARCHAR); INSERT INTO t VALUES ('abc'); SELECT regexp_count(s, 'a(b') FROM t; ``` on `main`: ``` Arrow error: Compute error: Regular expression did not compile: a(b ``` An invalid flag has the same problem. `regexp_count(s, 'a', 1, 'z')` reports `Regular expression did not compile: (?z)a`, which does not say that the flag is the cause. `compile_regex` receives a `regex::Error` that explains the cause, and discards it. Every other regex function keeps that text. For example `regexp_like` with a column pattern reports `regex parse error: ... error: unclosed group`, and `regexp_replace` returns the `regex::Error` itself. ## What changes are included in this PR? `compile_regex` puts the `regex` crate diagnosis in the message instead of the pattern text. The diagnosis contains the pattern, so no information is lost: ``` Arrow error: Compute error: Regular expression did not compile: regex parse error: a(b ^ error: unclosed group ``` This is one line of production code. The error type and planning-time validation of literal patterns, which are the other parts of https://github.com/apache/datafusion/issues/25351, are not addressed here. ## What is the testing strategy for this PR? New cases in `datafusion/sqllogictest/test_files/regexp/regexp_count.slt` and `regexp_instr.slt` cover an invalid pattern (column and literal argument), an invalid flag, and the unsupported `g` flag. The first three fail on `main`, because the message has no `regex parse error:` part. Also run locally: `cargo test -p datafusion-functions regex`, the `regexp` sqllogictest files, `cargo fmt --all -- --check`, and `cargo clippy --all-targets -p datafusion-functions -- -D warnings`. ## Are there any user-facing changes? The error message of `regexp_count` and `regexp_instr` for a pattern that does not compile now contains the reason. There are no API changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
