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 57ae4f49702 [SPARK-42324][SQL] Assign name to _LEGACY_ERROR_TEMP_1001 57ae4f49702 is described below commit 57ae4f49702d200585c56e3f000cca1d729f6f64 Author: itholic <haejoon....@databricks.com> AuthorDate: Tue Feb 14 10:22:35 2023 +0500 [SPARK-42324][SQL] Assign name to _LEGACY_ERROR_TEMP_1001 ### What changes were proposed in this pull request? This PR proposes to assign name to _LEGACY_ERROR_TEMP_1001, "UNRESOLVED_USING_COLUMN_FOR_JOIN". ### 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 #39963 from itholic/LEGACY_1001. Authored-by: itholic <haejoon....@databricks.com> Signed-off-by: Max Gekk <max.g...@gmail.com> --- core/src/main/resources/error/error-classes.json | 11 +++++----- .../spark/sql/catalyst/analysis/Analyzer.scala | 6 ++++-- .../spark/sql/errors/QueryCompilationErrors.scala | 8 +++---- .../analysis/ResolveNaturalJoinSuite.scala | 25 ++++++++++++++-------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/core/src/main/resources/error/error-classes.json b/core/src/main/resources/error/error-classes.json index e329932acf1..01fd43eec7f 100644 --- a/core/src/main/resources/error/error-classes.json +++ b/core/src/main/resources/error/error-classes.json @@ -1561,6 +1561,12 @@ ], "sqlState" : "42883" }, + "UNRESOLVED_USING_COLUMN_FOR_JOIN" : { + "message" : [ + "USING column <colName> cannot be resolved on the <side> side of the join. The <side>-side columns: [<suggestion>]." + ], + "sqlState" : "42703" + }, "UNSUPPORTED_DATATYPE" : { "message" : [ "Unsupported data type <typeName>." @@ -2175,11 +2181,6 @@ "LEGACY store assignment policy is disallowed in Spark data source V2. Please set the configuration <configKey> to other values." ] }, - "_LEGACY_ERROR_TEMP_1001" : { - "message" : [ - "USING column `<colName>` cannot be resolved on the <side> side of the join. The <side>-side columns: [<plan>]." - ] - }, "_LEGACY_ERROR_TEMP_1002" : { "message" : [ "Unable to generate an encoder for inner class `<className>` without access to the scope that this class was defined in.", diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala index eff8c114a97..46cc0b0fbf0 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala @@ -3450,12 +3450,14 @@ class Analyzer(override val catalogManager: CatalogManager) extends RuleExecutor val leftKeys = joinNames.map { keyName => left.output.find(attr => resolver(attr.name, keyName)).getOrElse { - throw QueryCompilationErrors.unresolvedUsingColForJoinError(keyName, left, "left") + throw QueryCompilationErrors.unresolvedUsingColForJoinError( + keyName, left.schema.fieldNames.sorted.map(toSQLId).mkString(", "), "left") } } val rightKeys = joinNames.map { keyName => right.output.find(attr => resolver(attr.name, keyName)).getOrElse { - throw QueryCompilationErrors.unresolvedUsingColForJoinError(keyName, right, "right") + throw QueryCompilationErrors.unresolvedUsingColForJoinError( + keyName, right.schema.fieldNames.sorted.map(toSQLId).mkString(", "), "right") } } val joinPairs = leftKeys.zip(rightKeys) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala index fbcffe04d32..9840ebf2b8a 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala @@ -194,13 +194,13 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase { } def unresolvedUsingColForJoinError( - colName: String, plan: LogicalPlan, side: String): Throwable = { + colName: String, suggestion: String, side: String): Throwable = { new AnalysisException( - errorClass = "_LEGACY_ERROR_TEMP_1001", + errorClass = "UNRESOLVED_USING_COLUMN_FOR_JOIN", messageParameters = Map( - "colName" -> colName, + "colName" -> toSQLId(colName), "side" -> side, - "plan" -> plan.output.map(_.name).mkString(", "))) + "suggestion" -> suggestion)) } def unresolvedAttributeError( diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ResolveNaturalJoinSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ResolveNaturalJoinSuite.scala index 2949c811bca..5c843d62d6d 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ResolveNaturalJoinSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ResolveNaturalJoinSuite.scala @@ -108,12 +108,16 @@ class ResolveNaturalJoinSuite extends AnalysisTest { } test("using unresolved attribute") { - assertAnalysisError( + assertAnalysisErrorClass( r1.join(r2, UsingJoin(Inner, Seq("d"))), - "USING column `d` cannot be resolved on the left side of the join" :: Nil) - assertAnalysisError( + expectedErrorClass = "UNRESOLVED_USING_COLUMN_FOR_JOIN", + expectedMessageParameters = Map( + "colName" -> "`d`", "side" -> "left", "suggestion" -> "`a`, `b`")) + assertAnalysisErrorClass( r1.join(r2, UsingJoin(Inner, Seq("b"))), - "USING column `b` cannot be resolved on the right side of the join" :: Nil) + expectedErrorClass = "UNRESOLVED_USING_COLUMN_FOR_JOIN", + expectedMessageParameters = Map( + "colName" -> "`b`", "side" -> "right", "suggestion" -> "`a`, `c`")) } test("using join with a case sensitive analyzer") { @@ -122,16 +126,19 @@ class ResolveNaturalJoinSuite extends AnalysisTest { val usingPlan = r1.join(r2, UsingJoin(Inner, Seq("a")), None) checkAnalysis(usingPlan, expected, caseSensitive = true) - assertAnalysisError( + assertAnalysisErrorClass( r1.join(r2, UsingJoin(Inner, Seq("A"))), - "USING column `A` cannot be resolved on the left side of the join" :: Nil) + expectedErrorClass = "UNRESOLVED_USING_COLUMN_FOR_JOIN", + expectedMessageParameters = Map( + "colName" -> "`A`", "side" -> "left", "suggestion" -> "`a`, `b`")) } test("using join on nested fields") { - assertAnalysisError( + assertAnalysisErrorClass( r5.join(r6, UsingJoin(Inner, Seq("d.f1"))), - "USING column `d.f1` cannot be resolved on the left side of the join. " + - "The left-side columns: [d]" :: Nil) + expectedErrorClass = "UNRESOLVED_USING_COLUMN_FOR_JOIN", + expectedMessageParameters = Map( + "colName" -> "`d`.`f1`", "side" -> "left", "suggestion" -> "`d`")) } test("using join with a case insensitive analyzer") { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org