Abhishek-Mohan opened a new pull request, #7740:
URL: https://github.com/apache/datafusion-comet/pull/7740

   ## Which issue does this PR close?
   
   Closes #7711.
   
   ## Rationale for this change
   
   With `spark.comet.expression.RegExpExtract.allowIncompatible` (or 
`RegExpExtractAll`) enabled, native `regexp_extract` and `regexp_extract_all` 
compile the pattern at the start of every batch, before looking at any row. 
Spark compiles it only for a row whose inputs are all non-null: 
`RegExpExtractBase` is null-intolerant, and the pattern is compiled in 
`getLastMatcher` / `RegExpUtils.initLastMatcherCode`, inside `nullSafeEval` / 
`nullSafeCodeGen`. This is the same on the 3.5, 4.0, 4.1, 4.2, 4.3, 4.4 and 4.x 
branches and on master, and nothing in it depends on ANSI mode.
   
   So when no subject row is non-null, Spark returns NULL whatever the pattern, 
while Comet fails the query if the pattern does not compile in the Rust `regex` 
crate. That includes patterns that are invalid in both engines, such as 
`'(unclosed'`, and patterns that Java accepts but Rust rejects, such as 
lookahead.
   
   ## What changes are included in this PR?
   
   - `regexp_extract_common.rs`: before compiling the pattern, `parse_args` 
returns the existing `ParsedArgs::NullResult` when the subject has no non-null 
row. That is a `Utf8` or `LargeUtf8` column with `null_count() == len()`, or a 
null `Utf8` or `LargeUtf8` literal. A column with no rows is included, so an 
empty batch also returns an empty result without compiling the pattern, as in 
Spark.
   - A batch with at least one non-null row still fails on an invalid pattern. 
Spark fails the task on the first such row and Comet fails the batch that 
contains it, so the same queries fail.
   - A subject of any other type still gets the existing "expects Utf8 or 
LargeUtf8 subject" error instead of becoming NULL.
   - The comment above the `idx` check now links #7725, as asked in the review 
of #7710. #7725 covers the remaining case for both checks: a non-null literal 
(scalar) subject in a batch with no rows is still evaluated, because Comet 
scalar functions do not receive the batch row count. That case is left to #7725.
   
   ## How are these changes tested?
   
   - Rust unit tests for both functions with the invalid pattern `'(unclosed'`. 
An all-null `Utf8` column, an all-null `LargeUtf8` column, an all-null slice of 
a column that has a value, a null `Utf8` literal, a null `LargeUtf8` literal 
and a column with no rows all return NULL (or an empty result). A valid pattern 
on an all-null column is not compiled (`compile_count() == 0`). One non-null 
row among nulls still fails with the `regexp` error, and an all-null `Int32` 
column still fails with the type error.
   - SQL file tests in `regexp_extract_enabled.sql` and 
`regexp_extract_all_enabled.sql`, using `expect_native`: each function over the 
NULL rows of the existing table (`WHERE s IS NULL`) with `'(unclosed'` and with 
the lookahead `'(?=\\d)\\w+'`.
   - Without the fix, the new SQL queries fail with "The value of parameter 
`regexp` in `regexp_extract` is invalid: '(unclosed'", with ANSI mode both off 
and on. With the fix, `./mvnw test -Dtest=none 
-Dsuites="org.apache.comet.CometSqlFileTestSuite regexp_extract"` passes all 5 
files, and `cargo test`, `cargo fmt` and `cargo clippy -D warnings` pass.
   


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

Reply via email to