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

maxgekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 59d14d73521 [SPARK-42842][SQL] Merge the error class 
_LEGACY_ERROR_TEMP_2006 into REGEX_GROUP_INDEX
59d14d73521 is described below

commit 59d14d7352109b6b14ae435073979437c857c99f
Author: Liang Yan <[email protected]>
AuthorDate: Sat May 6 09:10:53 2023 +0300

    [SPARK-42842][SQL] Merge the error class _LEGACY_ERROR_TEMP_2006 into 
REGEX_GROUP_INDEX
    
    ### What changes were proposed in this pull request?
    
    Merge the error class _LEGACY_ERROR_TEMP_2006 into REGEX_GROUP_INDEX.
    
    ### Why are the changes needed?
    
    Fix jira issue 
[SPARK-42842](https://issues.apache.org/jira/browse/SPARK-42842). The original 
name just a number, update it to an informal name.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Current tests covered it.
    
    Closes #41059 from liang3zy22/spark42842.
    
    Authored-by: Liang Yan <[email protected]>
    Signed-off-by: Max Gekk <[email protected]>
---
 core/src/main/resources/error/error-classes.json   |  5 ---
 .../catalyst/expressions/regexpExpressions.scala   |  6 +--
 .../spark/sql/errors/QueryExecutionErrors.scala    |  8 +---
 .../expressions/RegexpExpressionsSuite.scala       | 49 ++++++++++++++++++----
 .../sql-tests/results/regexp-functions.sql.out     | 44 +++++++++++++++----
 5 files changed, 79 insertions(+), 33 deletions(-)

diff --git a/core/src/main/resources/error/error-classes.json 
b/core/src/main/resources/error/error-classes.json
index 4eea5f9684e..abb843d519f 100644
--- a/core/src/main/resources/error/error-classes.json
+++ b/core/src/main/resources/error/error-classes.json
@@ -3752,11 +3752,6 @@
       "Type <dataType> does not support ordered operations."
     ]
   },
-  "_LEGACY_ERROR_TEMP_2006" : {
-    "message" : [
-      "The specified group index cannot be less than zero."
-    ]
-  },
   "_LEGACY_ERROR_TEMP_2011" : {
     "message" : [
       "Unexpected data type <dataType>."
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
index 2025a554998..7f37f02f5a9 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
@@ -747,10 +747,8 @@ object RegExpReplace {
 
 object RegExpExtractBase {
   def checkGroupIndex(prettyName: String, groupCount: Int, groupIndex: Int): 
Unit = {
-    if (groupIndex < 0) {
-      throw QueryExecutionErrors.regexGroupIndexLessThanZeroError
-    } else if (groupCount < groupIndex) {
-      throw QueryExecutionErrors.regexGroupIndexExceedGroupCountError(
+    if (groupIndex < 0 || groupCount < groupIndex) {
+      throw QueryExecutionErrors.invalidRegexGroupIndexError(
         prettyName, groupCount, groupIndex)
     }
   }
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
index 111f0391a72..bc51727f8fb 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
@@ -357,13 +357,7 @@ private[sql] object QueryExecutionErrors extends 
QueryErrorsBase {
       messageParameters = Map("dataType" -> dataType))
   }
 
-  def regexGroupIndexLessThanZeroError(): SparkIllegalArgumentException = {
-    new SparkIllegalArgumentException(
-      errorClass = "_LEGACY_ERROR_TEMP_2006",
-      messageParameters = Map.empty)
-  }
-
-  def regexGroupIndexExceedGroupCountError(
+  def invalidRegexGroupIndexError(
       funcName: String,
       groupCount: Int,
       groupIndex: Int): RuntimeException = {
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
index ace0c7959a1..c69944b2161 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
@@ -421,11 +421,26 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
         "groupIndex" -> "1"
       )
     )
-    checkExceptionInExpression[IllegalArgumentException](
-      expr, row11, "The specified group index cannot be less than zero")
-    checkExceptionInExpression[IllegalArgumentException](
-      expr, row12, "The specified group index cannot be less than zero")
-
+    checkErrorInExpression[SparkRuntimeException](
+      expr,
+      row11,
+      "INVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX",
+      Map("parameter" -> "`idx`",
+        "functionName" -> "`regexp_extract`",
+        "groupCount" -> "2",
+        "groupIndex" -> "-1"
+      )
+    )
+    checkErrorInExpression[SparkRuntimeException](
+      expr,
+      row12,
+      "INVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX",
+      Map("parameter" -> "`idx`",
+        "functionName" -> "`regexp_extract`",
+        "groupCount" -> "0",
+        "groupIndex" -> "-1"
+      )
+    )
     // Test escaping of arguments
     GenerateUnsafeProjection.generate(
       RegExpExtract(Literal("\"quote"), Literal("\"quote"), Literal(1)) :: Nil)
@@ -499,10 +514,26 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
         "groupIndex" -> "1"
       )
     )
-    checkExceptionInExpression[IllegalArgumentException](
-      expr, row12, "The specified group index cannot be less than zero")
-    checkExceptionInExpression[IllegalArgumentException](
-      expr, row13, "The specified group index cannot be less than zero")
+    checkErrorInExpression[SparkRuntimeException](
+      expr,
+      row12,
+      "INVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX",
+      Map("parameter" -> "`idx`",
+        "functionName" -> "`regexp_extract_all`",
+        "groupCount" -> "2",
+        "groupIndex" -> "-1"
+      )
+    )
+    checkErrorInExpression[SparkRuntimeException](
+      expr,
+      row13,
+      "INVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX",
+      Map("parameter" -> "`idx`",
+        "functionName" -> "`regexp_extract_all`",
+        "groupCount" -> "0",
+        "groupIndex" -> "-1"
+      )
+    )
   }
 
   test("SPLIT") {
diff --git 
a/sql/core/src/test/resources/sql-tests/results/regexp-functions.sql.out 
b/sql/core/src/test/resources/sql-tests/results/regexp-functions.sql.out
index c46b6590f9e..9154b14fbcb 100644
--- a/sql/core/src/test/resources/sql-tests/results/regexp-functions.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/regexp-functions.sql.out
@@ -66,9 +66,16 @@ SELECT regexp_extract('1a 2b 14m', '\\d+', -1)
 -- !query schema
 struct<>
 -- !query output
-org.apache.spark.SparkIllegalArgumentException
+org.apache.spark.SparkRuntimeException
 {
-  "errorClass" : "_LEGACY_ERROR_TEMP_2006"
+  "errorClass" : "INVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX",
+  "sqlState" : "22023",
+  "messageParameters" : {
+    "functionName" : "`regexp_extract`",
+    "groupCount" : "0",
+    "groupIndex" : "-1",
+    "parameter" : "`idx`"
+  }
 }
 
 
@@ -143,9 +150,16 @@ SELECT regexp_extract('1a 2b 14m', '(\\d+)([a-z]+)', -1)
 -- !query schema
 struct<>
 -- !query output
-org.apache.spark.SparkIllegalArgumentException
+org.apache.spark.SparkRuntimeException
 {
-  "errorClass" : "_LEGACY_ERROR_TEMP_2006"
+  "errorClass" : "INVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX",
+  "sqlState" : "22023",
+  "messageParameters" : {
+    "functionName" : "`regexp_extract`",
+    "groupCount" : "2",
+    "groupIndex" : "-1",
+    "parameter" : "`idx`"
+  }
 }
 
 
@@ -249,9 +263,16 @@ SELECT regexp_extract_all('1a 2b 14m', '\\d+', -1)
 -- !query schema
 struct<>
 -- !query output
-org.apache.spark.SparkIllegalArgumentException
+org.apache.spark.SparkRuntimeException
 {
-  "errorClass" : "_LEGACY_ERROR_TEMP_2006"
+  "errorClass" : "INVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX",
+  "sqlState" : "22023",
+  "messageParameters" : {
+    "functionName" : "`regexp_extract_all`",
+    "groupCount" : "0",
+    "groupIndex" : "-1",
+    "parameter" : "`idx`"
+  }
 }
 
 
@@ -326,9 +347,16 @@ SELECT regexp_extract_all('1a 2b 14m', '(\\d+)([a-z]+)', 
-1)
 -- !query schema
 struct<>
 -- !query output
-org.apache.spark.SparkIllegalArgumentException
+org.apache.spark.SparkRuntimeException
 {
-  "errorClass" : "_LEGACY_ERROR_TEMP_2006"
+  "errorClass" : "INVALID_PARAMETER_VALUE.REGEX_GROUP_INDEX",
+  "sqlState" : "22023",
+  "messageParameters" : {
+    "functionName" : "`regexp_extract_all`",
+    "groupCount" : "2",
+    "groupIndex" : "-1",
+    "parameter" : "`idx`"
+  }
 }
 
 


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

Reply via email to