cloud-fan commented on a change in pull request #34034:
URL: https://github.com/apache/spark/pull/34034#discussion_r716431440
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/JoinSuite.scala
##########
@@ -1402,4 +1402,73 @@ class JoinSuite extends QueryTest with
SharedSparkSession with AdaptiveSparkPlan
assertJoin(sql, classOf[ShuffledHashJoinExec])
}
}
+
+ test("SPARK-36794: Ignore duplicated key when building relation for
semi/anti hash join") {
+ withTable("t1", "t2") {
+ spark.range(10).map(i => (i.toString, i + 1)).toDF("c1",
"c2").write.saveAsTable("t1")
+ spark.range(10).map(i => ((i % 5).toString, i % 3)).toDF("c1",
"c2").write.saveAsTable("t2")
+
+ Seq("BROADCAST", "SHUFFLE_HASH").foreach {
+ joinHint =>
+ val semiJoinDFs = Seq(
+ // No join condition, ignore duplicated key.
+ (sql(
+ s"SELECT /*+ $joinHint(t2) */ t1.c1 FROM t1 LEFT SEMI JOIN t2 ON
t1.c1 = t2.c1"),
+ true),
+ // Have join condition on build join key only, ignore duplicated
key.
+ (sql(
+ s"""
+ |SELECT /*+ $joinHint(t2) */ t1.c1 FROM t1 LEFT SEMI JOIN t2
+ |ON t1.c1 = t2.c1 AND CAST(t1.c2 * 2 AS STRING) != t2.c1
+ """.stripMargin),
+ true),
+ // Have join condition on other build attribute beside join key,
do not ignore
+ // duplicated key.
+ (sql(
+ s"""
+ |SELECT /*+ $joinHint(t2) */ t1.c1 FROM t1 LEFT SEMI JOIN t2
+ |ON t1.c1 = t2.c1 AND t1.c2 * 100 != t2.c2
+ """.stripMargin),
+ false)
+ )
+ val antiJoinDFs = Seq(
Review comment:
can we generate anti join SQL query by `.replace("SEMI", "ANTI")`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]