Repository: spark Updated Branches: refs/heads/master 7935c8470 -> 2f8776cca
[SPARK-18674][SQL][FOLLOW-UP] improve the error message of using join ### What changes were proposed in this pull request? Added a test case for using joins with nested fields. ### How was this patch tested? N/A Author: gatorsmile <[email protected]> Closes #16110 from gatorsmile/followup-18674. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/2f8776cc Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/2f8776cc Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/2f8776cc Branch: refs/heads/master Commit: 2f8776ccad532fbed17381ff97d302007918b8d8 Parents: 7935c84 Author: gatorsmile <[email protected]> Authored: Fri Dec 2 22:12:19 2016 +0800 Committer: Wenchen Fan <[email protected]> Committed: Fri Dec 2 22:12:19 2016 +0800 ---------------------------------------------------------------------- .../spark/sql/catalyst/analysis/Analyzer.scala | 8 ++++---- .../catalyst/analysis/ResolveNaturalJoinSuite.scala | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/2f8776cc/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala ---------------------------------------------------------------------- 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 931e659..8faf0ed 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 @@ -1974,14 +1974,14 @@ class Analyzer( condition: Option[Expression]) = { val leftKeys = joinNames.map { keyName => left.output.find(attr => resolver(attr.name, keyName)).getOrElse { - throw new AnalysisException(s"USING column `$keyName` can not be resolved with the " + - s"left join side, the left output is: [${left.output.map(_.name).mkString(", ")}]") + throw new AnalysisException(s"USING column `$keyName` cannot be resolved on the left " + + s"side of the join. The left-side columns: [${left.output.map(_.name).mkString(", ")}]") } } val rightKeys = joinNames.map { keyName => right.output.find(attr => resolver(attr.name, keyName)).getOrElse { - throw new AnalysisException(s"USING column `$keyName` can not be resolved with the " + - s"right join side, the right output is: [${right.output.map(_.name).mkString(", ")}]") + throw new AnalysisException(s"USING column `$keyName` cannot be resolved on the right " + + s"side of the join. The right-side columns: [${right.output.map(_.name).mkString(", ")}]") } } val joinPairs = leftKeys.zip(rightKeys) http://git-wip-us.apache.org/repos/asf/spark/blob/2f8776cc/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ResolveNaturalJoinSuite.scala ---------------------------------------------------------------------- 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 1421d36..e449b96 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 @@ -28,6 +28,7 @@ class ResolveNaturalJoinSuite extends AnalysisTest { lazy val a = 'a.string lazy val b = 'b.string lazy val c = 'c.string + lazy val d = 'd.struct('f1.int, 'f2.long) lazy val aNotNull = a.notNull lazy val bNotNull = b.notNull lazy val cNotNull = c.notNull @@ -35,6 +36,8 @@ class ResolveNaturalJoinSuite extends AnalysisTest { lazy val r2 = LocalRelation(c, a) lazy val r3 = LocalRelation(aNotNull, bNotNull) lazy val r4 = LocalRelation(cNotNull, bNotNull) + lazy val r5 = LocalRelation(d) + lazy val r6 = LocalRelation(d) test("natural/using inner join") { val naturalPlan = r1.join(r2, NaturalJoin(Inner), None) @@ -108,10 +111,10 @@ class ResolveNaturalJoinSuite extends AnalysisTest { test("using unresolved attribute") { assertAnalysisError( r1.join(r2, UsingJoin(Inner, Seq("d"))), - "USING column `d` can not be resolved with the left join side" :: Nil) + "USING column `d` cannot be resolved on the left side of the join" :: Nil) assertAnalysisError( r1.join(r2, UsingJoin(Inner, Seq("b"))), - "USING column `b` can not be resolved with the right join side" :: Nil) + "USING column `b` cannot be resolved on the right side of the join" :: Nil) } test("using join with a case sensitive analyzer") { @@ -122,7 +125,14 @@ class ResolveNaturalJoinSuite extends AnalysisTest { assertAnalysisError( r1.join(r2, UsingJoin(Inner, Seq("A"))), - "USING column `A` can not be resolved with the left join side" :: Nil) + "USING column `A` cannot be resolved on the left side of the join" :: Nil) + } + + test("using join on nested fields") { + assertAnalysisError( + 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) } test("using join with a case insensitive analyzer") { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
