Skip to content

[Feature](func) Support the third argument for regexp_extract_all and regexp_extract_all_array#66050

Open
ccl125 wants to merge 1 commit into
apache:masterfrom
ccl125:feat/regexp-extract-all-group-index
Open

[Feature](func) Support the third argument for regexp_extract_all and regexp_extract_all_array#66050
ccl125 wants to merge 1 commit into
apache:masterfrom
ccl125:feat/regexp-extract-all-group-index

Conversation

@ccl125

@ccl125 ccl125 commented Jul 25, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: related #48203 (Spark: regexp_extract_all for the third argument)

Problem Summary:

regexp_extract_all / regexp_extract_all_array only accepted 2 arguments and always extracted the first capturing group. This PR adds the optional third group argument, following Spark semantics:

  • regexp_extract_all(str, pattern) — unchanged, extracts group 1 (the FE pads the default index literal, same as substring does)
  • regexp_extract_all(str, pattern, 0) — extracts the whole match (also works for patterns without capturing groups)
  • regexp_extract_all(str, pattern, N) — extracts capturing group N
  • group index out of range → empty result; negative index → NULL

Implementation:

  • FE: RegexpExtractAll / RegexpExtractAllArray gain 3-arg signatures; the 2-arg constructor pads BigIntLiteral(1) (mirrors Substring), and the misleading BinaryExpression shape is dropped (mirrors Substring as well)
  • BE: RegexpExtractEngine::match_all_and_extract takes a group index; RegexpExtractAllImpl handles the third column (const and non-const) per row

Release note

Support the third argument (group index) for regexp_extract_all and regexp_extract_all_array.

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:

    New BE unit cases in function_like_test.cpp cover group 0 / other groups / out-of-range / negative index for both functions; existing 2-arg cases were ported to the normalized 3-arg form with unchanged expectations. New regression cases added to test_string_function_regexp.

  • Behavior changed:

    • No.
    • Yes.

    2-argument calls keep the exact previous behavior (group 1 extraction, empty result when the pattern has no capturing group).

  • Does this need documentation?

    • No.
    • Yes. Will follow up with a docs PR to apache/doris-website if this is accepted.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

… regexp_extract_all_array

Add an optional group-index argument (Spark semantics, default 1) to
regexp_extract_all and regexp_extract_all_array. Index 0 extracts the
whole match, a positive index extracts the corresponding capturing
group, an out-of-range index yields an empty result, and a negative
index yields NULL. Two-argument calls are normalized in the FE by
padding the default index, keeping existing behavior unchanged.
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants