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 d2fc1992058 [SPARK-41489][SQL] Assign name to _LEGACY_ERROR_TEMP_2415 d2fc1992058 is described below commit d2fc19920588f2f6c83c31a9519702f9416190fe Author: itholic <haejoon....@databricks.com> AuthorDate: Sun Jan 29 08:45:14 2023 +0300 [SPARK-41489][SQL] Assign name to _LEGACY_ERROR_TEMP_2415 ### What changes were proposed in this pull request? This PR proposes to assign name to _LEGACY_ERROR_TEMP_2415, "DATATYPE_MISMATCH.FILTER_NOT_BOOLEAN". ### Why are the changes needed? We should assign proper name to _LEGACY_ERROR_TEMP_* ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? `./build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite*` Closes #39701 from itholic/LEGACY_2415. Authored-by: itholic <haejoon....@databricks.com> Signed-off-by: Max Gekk <max.g...@gmail.com> --- core/src/main/resources/error/error-classes.json | 10 +++++----- .../apache/spark/sql/catalyst/analysis/CheckAnalysis.scala | 7 ++++--- .../spark/sql/catalyst/analysis/AnalysisErrorSuite.scala | 5 +++-- .../apache/spark/sql/catalyst/analysis/AnalysisSuite.scala | 14 ++++++++++++++ .../optimizer/ReplaceNullWithFalseInPredicateSuite.scala | 11 +++++++---- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/core/src/main/resources/error/error-classes.json b/core/src/main/resources/error/error-classes.json index ae766de3e20..936f996f3a4 100644 --- a/core/src/main/resources/error/error-classes.json +++ b/core/src/main/resources/error/error-classes.json @@ -265,6 +265,11 @@ "Input to <functionName> should all be the same type, but it's <dataType>." ] }, + "FILTER_NOT_BOOLEAN" : { + "message" : [ + "Filter expression <filter> of type <type> is not a boolean." + ] + }, "HASH_MAP_TYPE" : { "message" : [ "Input to the function <functionName> cannot contain elements of the \"MAP\" type. In Spark, same maps may have different hashcode, thus hash expressions are prohibited on \"MAP\" elements. To restore previous behavior set \"spark.sql.legacy.allowHashOnMapType\" to \"true\"." @@ -5175,11 +5180,6 @@ "Event time must be defined on a window or a timestamp, but <evName> is of type <evType>." ] }, - "_LEGACY_ERROR_TEMP_2415" : { - "message" : [ - "filter expression '<filter>' of type <type> is not a boolean." - ] - }, "_LEGACY_ERROR_TEMP_2416" : { "message" : [ "join condition '<join>' of type <type> is not a boolean." diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala index d5ef71adc4f..276bf714a34 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala @@ -355,10 +355,11 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB } case f: Filter if f.condition.dataType != BooleanType => f.failAnalysis( - errorClass = "_LEGACY_ERROR_TEMP_2415", + errorClass = "DATATYPE_MISMATCH.FILTER_NOT_BOOLEAN", messageParameters = Map( - "filter" -> f.condition.sql, - "type" -> f.condition.dataType.catalogString)) + "sqlExpr" -> f.expressions.map(toSQLExpr).mkString(","), + "filter" -> toSQLExpr(f.condition), + "type" -> toSQLType(f.condition.dataType))) case j @ Join(_, _, _, Some(condition), _) if condition.dataType != BooleanType => j.failAnalysis( diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala index faa8c1f4558..56bb8b0ccc2 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala @@ -349,10 +349,11 @@ class AnalysisErrorSuite extends AnalysisTest { "UNRESOLVED_COLUMN.WITH_SUGGESTION", Map("objectName" -> "`b`", "proposal" -> "`a`, `c`, `a3`")) - errorTest( + errorClassTest( "non-boolean filters", testRelation.where(Literal(1)), - "filter" :: "'1'" :: "not a boolean" :: Literal(1).dataType.simpleString :: Nil) + errorClass = "DATATYPE_MISMATCH.FILTER_NOT_BOOLEAN", + messageParameters = Map("sqlExpr" -> "\"1\"", "filter" -> "\"1\"", "type" -> "\"INT\"")) errorTest( "non-boolean join conditions", diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala index 6dfbf12bbd7..0a3023a7af8 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala @@ -1329,4 +1329,18 @@ class AnalysisSuite extends AnalysisTest with Matchers { args = Map("param1" -> Literal(10), "param2" -> Literal(20))), parsePlan("SELECT c FROM a WHERE c < 20")) } + + test("SPARK-41489: type of filter expression should be a bool") { + assertAnalysisErrorClass(parsePlan( + s""" + |WITH t1 as (SELECT 1 user_id) + |SELECT * + |FROM t1 + |WHERE 'true'""".stripMargin), + expectedErrorClass = "DATATYPE_MISMATCH.FILTER_NOT_BOOLEAN", + expectedMessageParameters = Map( + "sqlExpr" -> "\"true\"", "filter" -> "\"true\"", "type" -> "\"STRING\"") + , + queryContext = Array(ExpectedContext("SELECT *\nFROM t1\nWHERE 'true'", 31, 59))) + } } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ReplaceNullWithFalseInPredicateSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ReplaceNullWithFalseInPredicateSuite.scala index 4c1a8a53ac2..7d037799fba 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ReplaceNullWithFalseInPredicateSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ReplaceNullWithFalseInPredicateSuite.scala @@ -55,10 +55,13 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest { } test("Not expected type - replaceNullWithFalse") { - val e = intercept[AnalysisException] { - testFilter(originalCond = Literal(null, IntegerType), expectedCond = FalseLiteral) - }.getMessage - assert(e.contains("'CAST(NULL AS INT)' of type int is not a boolean")) + checkError( + exception = intercept[AnalysisException] { + testFilter(originalCond = Literal(null, IntegerType), expectedCond = FalseLiteral) + }, + errorClass = "DATATYPE_MISMATCH.FILTER_NOT_BOOLEAN", + parameters = Map("sqlExpr" -> "\"NULL\"", "filter" -> "\"NULL\"", "type" -> "\"INT\"") + ) } test("replace null in branches of If") { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org