This is an automated email from the ASF dual-hosted git repository.
wenchen 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 f3a82b32a00 [SPARK-41983][SQL] Rename & improve error message for
`NULL_COMPARISON_RESULT`
f3a82b32a00 is described below
commit f3a82b32a00fea5f0068306764b887f729d18d8c
Author: itholic <[email protected]>
AuthorDate: Wed Jan 18 17:24:40 2023 +0800
[SPARK-41983][SQL] Rename & improve error message for
`NULL_COMPARISON_RESULT`
### What changes were proposed in this pull request?
This PR proposes to rename & improve error message for
`NULL_COMPARISON_RESULT`
### Why are the changes needed?
We should have proper name and error message for error classes.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
`./build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite*"`
Closes #39506 from itholic/NULL_COMPARISON_RESULT.
Authored-by: itholic <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
---
core/src/main/resources/error/error-classes.json | 11 +++++------
.../spark/sql/catalyst/expressions/higherOrderFunctions.scala | 2 +-
.../org/apache/spark/sql/errors/QueryExecutionErrors.scala | 6 +++---
.../sql/catalyst/expressions/HigherOrderFunctionsSuite.scala | 7 +++++--
4 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/core/src/main/resources/error/error-classes.json
b/core/src/main/resources/error/error-classes.json
index e3904c1fe5a..78b1bf0743d 100644
--- a/core/src/main/resources/error/error-classes.json
+++ b/core/src/main/resources/error/error-classes.json
@@ -134,6 +134,11 @@
],
"sqlState" : "42703"
},
+ "COMPARATOR_RETURNS_NULL" : {
+ "message" : [
+ "The comparator has returned a NULL for a comparison between
<firstValue> and <secondValue>. It should return a positive integer for
\"greater than\", 0 for \"equal\" and a negative integer for \"less than\". To
revert to deprecated behavior where NULL is treated as 0 (equal), you must set
\"spark.sql.legacy.allowNullComparisonResultInArraySort\" to \"true\"."
+ ]
+ },
"CONCURRENT_QUERY" : {
"message" : [
"Another instance of this query was just started by a concurrent
session."
@@ -1043,12 +1048,6 @@
],
"sqlState" : "42000"
},
- "NULL_COMPARISON_RESULT" : {
- "message" : [
- "The comparison result is null. If you want to handle null as 0 (equal),
you can set \"spark.sql.legacy.allowNullComparisonResultInArraySort\" to
\"true\"."
- ],
- "sqlState" : "560A9"
- },
"NULL_MAP_KEY" : {
"message" : [
"Cannot use null as map key."
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/higherOrderFunctions.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/higherOrderFunctions.scala
index da57538a8b4..c2db38bae45 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/higherOrderFunctions.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/higherOrderFunctions.scala
@@ -452,7 +452,7 @@ case class ArraySort(
secondElemVar.value.set(o2)
val cmp = f.eval(inputRow)
if (!allowNullComparisonResult && cmp == null) {
- throw QueryExecutionErrors.nullComparisonResultError()
+ throw QueryExecutionErrors.comparatorReturnsNull(o1.toString,
o1.toString)
}
cmp.asInstanceOf[Int]
}
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 b89c624870e..8128c460602 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
@@ -2756,10 +2756,10 @@ private[sql] object QueryExecutionErrors extends
QueryErrorsBase {
summary = getSummary(context))
}
- def nullComparisonResultError(): Throwable = {
+ def comparatorReturnsNull(firstValue: String, secondValue: String):
Throwable = {
new SparkException(
- errorClass = "NULL_COMPARISON_RESULT",
- messageParameters = Map.empty,
+ errorClass = "COMPARATOR_RETURNS_NULL",
+ messageParameters = Map("firstValue" -> firstValue, "secondValue" ->
secondValue),
cause = null)
}
diff --git
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/HigherOrderFunctionsSuite.scala
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/HigherOrderFunctionsSuite.scala
index fb77f1a482c..383010427b1 100644
---
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/HigherOrderFunctionsSuite.scala
+++
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/HigherOrderFunctionsSuite.scala
@@ -851,8 +851,11 @@ class HigherOrderFunctionsSuite extends SparkFunSuite with
ExpressionEvalHelper
withSQLConf(
SQLConf.LEGACY_ALLOW_NULL_COMPARISON_RESULT_IN_ARRAY_SORT.key ->
"false") {
- checkExceptionInExpression[SparkException](
- arraySort(Literal.create(Seq(3, 1, 1, 2)), comparator), "The
comparison result is null")
+ checkErrorInExpression[SparkException](
+ expression = arraySort(Literal.create(Seq(3, 1, 1, 2)), comparator),
+ errorClass = "COMPARATOR_RETURNS_NULL",
+ parameters = Map("firstValue" -> "1", "secondValue" -> "1")
+ )
}
withSQLConf(
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]