comphead commented on code in PR #7736:
URL: https://github.com/apache/datafusion-comet/pull/7736#discussion_r4743954943
##########
native/spark-expr/src/string_funcs/regexp_extract_all.rs:
##########
@@ -503,6 +503,79 @@ mod tests {
assert!(err.to_string().contains("`regexp`"));
}
+ #[test]
+ fn invalid_regex_on_all_null_subject_returns_null() {
+ let result = run(vec![array(vec![None, None]), pattern(r"(unclosed"),
idx(1)]).unwrap();
+ assert_eq!(result, vec![None, None]);
+ let large =
ColumnarValue::Array(Arc::new(LargeStringArray::from(vec![None::<&str>])));
+ let result = run(vec![large, pattern(r"(unclosed"), idx(1)]).unwrap();
+ assert_eq!(result, vec![None]);
+ }
+
+ #[test]
+ fn invalid_regex_on_null_scalar_subject_returns_null() {
+ let null = ColumnarValue::Scalar(ScalarValue::Utf8(None));
+ let result = run(vec![null, pattern(r"(unclosed"), idx(1)]).unwrap();
+ assert_eq!(result, vec![None]);
+ }
+
+ #[test]
+ fn invalid_regex_errors_when_one_row_is_non_null() {
+ let err = call_raw(&[
+ array(vec![None, Some("abc")]),
+ pattern(r"(unclosed"),
+ idx(1),
+ ])
+ .err()
+ .unwrap();
+ assert!(err.to_string().contains("`regexp`"));
+ }
Review Comment:
Same as in `regexp_extract.rs`. The first three tests here are covered by
`invalid_regex_without_a_non_null_subject_returns_null` and the block is a copy
of the other file's.
##########
native/spark-expr/src/string_funcs/regexp_extract.rs:
##########
@@ -356,6 +356,78 @@ mod tests {
assert!(err.to_string().contains("`regexp`"));
}
+ #[test]
+ fn invalid_regex_on_all_null_subject_returns_null() {
+ let result = run(vec![array(vec![None, None]), pattern(r"(unclosed"),
idx(1)]).unwrap();
+ assert_eq!(result, vec![None, None]);
+ let large =
ColumnarValue::Array(Arc::new(LargeStringArray::from(vec![None::<&str>])));
+ let result = run(vec![large, pattern(r"(unclosed"), idx(1)]).unwrap();
+ assert_eq!(result, vec![None]);
+ }
+
+ #[test]
+ fn invalid_regex_on_null_scalar_subject_returns_null() {
+ let null = ColumnarValue::Scalar(ScalarValue::Utf8(None));
+ let result = run(vec![null, pattern(r"(unclosed"), idx(1)]).unwrap();
+ assert_eq!(result, vec![None]);
+ }
+
+ #[test]
+ fn invalid_regex_errors_when_one_row_is_non_null() {
+ let err = call_raw(&[
+ array(vec![None, Some("abc")]),
+ pattern(r"(unclosed"),
+ idx(1),
+ ])
+ .err()
+ .unwrap();
+ assert!(err.to_string().contains("`regexp`"));
+ }
Review Comment:
These three tests are subsumed by
`invalid_regex_without_a_non_null_subject_returns_null` right below, which
already covers `Utf8` and `LargeUtf8` all-null arrays, the null scalar, and the
error when one row is non-null. The same four-test block is also repeated in
`regexp_extract_all.rs`. The behavior lives in `parse_args`, so a single test
of `parse_args` in `regexp_extract_common.rs` plus one short test per function
would cover both without the copy.
##########
spark/src/test/resources/sql-tests/expressions/string/regexp_extract_enabled.sql:
##########
@@ -157,6 +157,22 @@ SELECT regexp_extract(s, '\\d+', 1) FROM
test_regexp_extract_one_digit
query expect_error(regexp_extract)
SELECT regexp_extract(s, '(unclosed', 1) FROM test_regexp_extract_enabled
+-- Spark compiles the pattern only on a row whose subject is non-null, so an
invalid pattern
+-- is not an error when every subject row is null. The same holds for a
pattern that only
+-- Rust regex rejects.
+statement
+CREATE TABLE test_regexp_extract_all_null(s string) USING parquet
+
+statement
+INSERT INTO test_regexp_extract_all_null VALUES (NULL), (NULL)
+
+query expect_native(regexp_extract)
+SELECT regexp_extract(s, '(unclosed', 1), regexp_extract(s, '(?=\\d)\\w+', 0)
+FROM test_regexp_extract_all_null
Review Comment:
The new `test_regexp_extract_all_null` table and its two statements are not
needed. The `WHERE s IS NULL` query below already gives native an all-null
batch from the existing table, and line 139 of this file uses the same shape.
Putting both expressions (`'(unclosed'` and the lookahead) in that one query
removes the table and one `query`.
##########
spark/src/test/resources/sql-tests/expressions/string/regexp_extract_all_enabled.sql:
##########
@@ -155,6 +155,22 @@ SELECT regexp_extract_all(s, '\\d+', 1) FROM
test_regexp_extract_all_one_digit
query expect_error(regexp_extract_all)
SELECT regexp_extract_all(s, '(unclosed', 1) FROM
test_regexp_extract_all_enabled
+-- Spark compiles the pattern only on a row whose subject is non-null, so an
invalid pattern
+-- is not an error when every subject row is null. The same holds for a
pattern that only
+-- Rust regex rejects.
+statement
+CREATE TABLE test_regexp_extract_all_all_null(s string) USING parquet
+
+statement
+INSERT INTO test_regexp_extract_all_all_null VALUES (NULL), (NULL)
+
+query expect_native(regexp_extract_all)
+SELECT regexp_extract_all(s, '(unclosed', 1), regexp_extract_all(s,
'(?=\\d)\\w+', 0)
+FROM test_regexp_extract_all_all_null
Review Comment:
Same as in `regexp_extract_enabled.sql`. The `WHERE s IS NULL` query over
the existing table covers the all-null batch, so the
`test_regexp_extract_all_all_null` table is not needed. Both patterns can go in
that one query.
--
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]