Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Apache DataFusion is missing a
regexp_extractscalar function that is available in Apache Spark (viafunctions.regexp_extract). This function is commonly used in ETL pipelines to extract specific capture groups from strings using regular expressions. Adding it improves compatibility with Spark workloads migrating to DataFusion.What changes are included in this PR?
regexp_extract(str, regexp, idx)indatafusion/functions/src/regex/regexpextract.rsUtf8,LargeUtf8, andUtf8Viewstring typesidx(Int64) selects the capture group:0returns the full match,≥1returns the corresponding group""when the pattern does not match or the requested group is absent (Spark-compatible behavior)NULLwhen the input string isNULLidxvaluesidxvalues (column argument), not just scalar literalscompile_and_cache_regexhelper for regex compilation and cachingdatafusion/functions/src/regex/mod.rsregexp_extractusage examples todatafusion-examples/examples/builtin_functions/regexp.rsAre these changes tested?
Yes. Ten unit tests are included in
regexpextract.rscovering:test_basic_grouptest_idx_zero_returns_whole_matchidx=0returns the full matchtest_no_match_returns_empty_string""test_null_input_returns_nulltest_empty_pattern_returns_empty_string""test_idx_out_of_range_returns_empty_string""test_negative_idx_returns_erroridx→ errortest_multiple_groupstest_idx_as_columnidxas a per-row column (not scalar)test_batch_mixed_nullsAre there any user-facing changes?
Yes. A new scalar function
regexp_extract(str, regexp, idx)is now available in both SQL and the DataFrame API.