linrrzqqq commented on code in PR #66050:
URL: https://github.com/apache/doris/pull/66050#discussion_r3679994842


##########
be/src/exprs/function/function_regexp.cpp:
##########
@@ -136,13 +136,17 @@ struct RegexpExtractEngine {
         return false;
     }
 
-    // Match all occurrences and extract the first capturing group
-    void match_all_and_extract(const char* data, size_t size,
+    // Match all occurrences and extract the capturing group with the given 
index.
+    // index 0 means the whole match, 1 means the first capturing group (the 
default), and so on.
+    void match_all_and_extract(const char* data, size_t size, int index,
                                std::vector<std::string>& results) const {
+        if (index < 0) {
+            return;
+        }
         if (is_re2()) {
             int max_matches = 1 + re2_regex->NumberOfCapturingGroups();
-            if (max_matches < 2) {
-                return; // No capturing groups
+            if (index >= max_matches) {

Review Comment:
   The behavior for `idx >= max_matches || index < 0` better refer to Spark 
throwing an error.
   
   ```sql
   spark-sql (default)> SELECT regexp_extract_all('100-200, 300-400', 
'(\\d+)-(\\d+)', -1); 
   [INVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX] The value of parameter(s) `idx` 
in `regexp_extract_all` is invalid: Expects group index between 0 and 2, but 
got -1. SQLSTATE: 22023
   ```



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