This is an automated email from the ASF dual-hosted git repository.

exmy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 315117dc49 [GLUTEN-13593][CH] Fix regexp_extract for patterns with 
escaped brackets in character class (#13594)
315117dc49 is described below

commit 315117dc497da082059348d0f555d4002bc3da5e
Author: exmy <[email protected]>
AuthorDate: Mon Nov 9 17:20:36 2026 +0800

    [GLUTEN-13593][CH] Fix regexp_extract for patterns with escaped brackets in 
character class (#13594)
---
 .../GlutenClickhouseStringFunctionsSuite.scala      | 21 +++++++++++++++++++++
 .../scalar_function_parser/regexp_extract.cpp       | 17 +++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git 
a/backends-clickhouse/src/test/scala/org/apache/gluten/execution/compatibility/GlutenClickhouseStringFunctionsSuite.scala
 
b/backends-clickhouse/src/test/scala/org/apache/gluten/execution/compatibility/GlutenClickhouseStringFunctionsSuite.scala
index 32f5ed4489..5b607a3b5b 100644
--- 
a/backends-clickhouse/src/test/scala/org/apache/gluten/execution/compatibility/GlutenClickhouseStringFunctionsSuite.scala
+++ 
b/backends-clickhouse/src/test/scala/org/apache/gluten/execution/compatibility/GlutenClickhouseStringFunctionsSuite.scala
@@ -107,6 +107,27 @@ class GlutenClickhouseStringFunctionsSuite extends 
GlutenClickHouseWholeStageTra
     }
   }
 
+  test("GLUTEN-13593: regexp_extract with escaped bracket in character class") 
{
+    withTable("regexp_extract_escaped_bracket") {
+      sql("create table regexp_extract_escaped_bracket(a String) using 
parquet")
+      sql("""
+            |insert into regexp_extract_escaped_bracket
+            | values ('[com.example.demo.AlphaController viewDidAppear:]'),
+            |  ('[com.example.demo.BetaViewController]'), ('[123-456]')
+            |""".stripMargin)
+
+      val sql_str =
+        """select
+          |    regexp_extract(a, '\\[(?:.*\\.)?([^\\.\\s\\]]+)', 1)
+          |  , regexp_extract(a, '\\[([0-9-]+)\\]', 1)
+          |  , regexp_extract(a, '[\\[]', 0)
+          |  from regexp_extract_escaped_bracket
+          """.stripMargin
+
+      runQueryAndCompare(sql_str) { _ => }
+    }
+  }
+
   test("GLUTEN-8325 $. missmatched") {
     withTable("regexp_string_end") {
       sql("create table regexp_string_end(a String) using parquet")
diff --git 
a/cpp-ch/local-engine/Parser/scalar_function_parser/regexp_extract.cpp 
b/cpp-ch/local-engine/Parser/scalar_function_parser/regexp_extract.cpp
index 5d7059ae6c..837f02ff6f 100644
--- a/cpp-ch/local-engine/Parser/scalar_function_parser/regexp_extract.cpp
+++ b/cpp-ch/local-engine/Parser/scalar_function_parser/regexp_extract.cpp
@@ -109,8 +109,25 @@ private:
         strs.emplace("");
         bool nead_right_bracket = false;
 
+        auto copy_current = [&]()
+        {
+            strs.top() += *buf.position();
+            ++buf.position();
+        };
+
         while (!buf.eof())
         {
+            // Keep "\" plus the following character as a single unit, so that 
escaped brackets such
+            // as "\[" and "\]" (especially "\]" inside a character class, 
e.g. "[^\.\s\]]") are not
+            // mistaken for character class boundaries. See GLUTEN-13593.
+            if (*buf.position() == '\\')
+            {
+                copy_current();
+                if (!buf.eof())
+                    copy_current();
+                continue;
+            }
+
             if (*buf.position() == '[')
             {
                 strs.emplace("");


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to