feat(spark): add Spark-compatible regexp_extract function #73
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 474 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.369
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #73"
general
weight: 0.35
kosiew
Closes #4.
Summary
regexp_extract(str, regexp[, idx]), ported from DataFusion Comet'sstring_funcs/regexp_extract.rs. Part of #174.idx(default 1, 0 is the whole match) of the first match. NULL if any argument is NULL; empty string for no match or a group that did not participate.idxoutside0..=groupCountraisesINVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX, but only on rows that match; a row that does not match returns an empty string. The error class matches Spark 3.5 and later (3.4 used_LEGACY_ERROR_TEMP_2006/2007).INVALID_PARAMETER_VALUE.PATTERN, with the pattern quoted like Spark'stoSQLValue. A NULL row is not checked, as in Spark, so an invalid pattern is only reported on a row it is applied to. For the same reason a literal pattern is not validated at planning time.strandregexpof other types (numbers, binary, ...) are cast to strings, and numeric or stringidxis cast to INT. Unsupported types are plan errors.regexpandidxdo not have to be literals. A literal pattern is compiled once and kept in a small cache on the UDF, keyed by pattern, so later batches reuse it. A column of patterns reuses the last compiled pattern across rows.Utf8,LargeUtf8orUtf8Viewforstrand a pattern column. The result is alwaysUtf8.regexandregex-syntax(already in the lock file throughregex) as direct dependencies.#[user_doc].Known gaps
Patterns use the Rust
regexengine, notjava.util.regex. A shared Java-compatible regex helper is proposed in #255 and would also serve #257 and #259. Until then:\Q...\E,\Z,\h,(?>...),(?d)) and patterns over the Rust compiled-size limit raise a not-implemented "Unsupported regex pattern" error, where Spark evaluates them. A rejected pattern is classified withregex_syntax: only the syntax errors Java also raises areINVALID_PARAMETER_VALUE.PATTERN.Uflag, POSIX classes in brackets ([[:alpha:]]), the class operators--and~~,\<and\>, and Java's ASCII-only POSIX names in\p{..}(\p{Alpha}).INVALID_PARAMETER_VALUE.PATTERN, as in Spark: theRflag,\b{start}and the other\b{...}boundaries,(?P<name>...), and group names that are not an ASCII letter followed by letters and digits.\p{..}names that Rust knows and Java does not, such as\p{Letter}and\p{Latin}, are accepted where Spark raises an error.idx, returns NULL for a malformed stringidx, and casts NaN to 0. DataFusion's cast errors instead (#88).a++as(a+)+), so(a++a)matches where Java does not.\d,\w,\smatch Unicode; Java's match ASCII only..matches\r; Java's does not.$matches only at the end of input; Java's also matches before a final line terminator.(?i)uses Unicode case folding (kmatches the Kelvin sign); Java folds ASCII only by default.Each difference is recorded in the
.sltfile as a commented-out query with Spark 4.2.0's result.Testing
string/regexp_extract.slt. Expected values come from Spark'sregexp-functions.sql.outgolden file or were verified against Spark 4.2.0 with PySpark.cargo clippy --all-targets --all-features -- -D warnings,cargo test -p datafusion-sparkandcargo test -p datafusion-spark-sqllogictestpass.