cloud-fan commented on a change in pull request #31908: URL: https://github.com/apache/spark/pull/31908#discussion_r640358612
########## File path: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/AggregateOptimizeSuite.scala ########## @@ -71,4 +74,65 @@ class AggregateOptimizeSuite extends AnalysisTest { comparePlans(optimized, correctAnswer) } + + test("SPARK-34808: Remove left join if it only has distinct on left side") { + val x = testRelation.subquery('x) + val y = testRelation.subquery('y) + val query = Distinct(x.join(y, LeftOuter, Some("x.a".attr === "y.a".attr)).select("x.b".attr)) + + Seq(-1, 10000).foreach { autoBroadcastJoinThreshold => + withSQLConf(AUTO_BROADCASTJOIN_THRESHOLD.key -> s"$autoBroadcastJoinThreshold") { + val correctAnswer = if (autoBroadcastJoinThreshold < 0) { + x.select("x.b".attr).groupBy("x.b".attr)("x.b".attr) + } else { + Aggregate(query.child.output, query.child.output, query.child) + } + comparePlans(Optimize.execute(query.analyze), correctAnswer.analyze) + } + } + } + + test("SPARK-34808: Remove right join if it only has distinct on right side") { + val x = testRelation.subquery('x) + val y = testRelation.subquery('y) + val query = Distinct(x.join(y, RightOuter, Some("x.a".attr === "y.a".attr)).select("y.b".attr)) + + Seq(-1, 10000).foreach { autoBroadcastJoinThreshold => + withSQLConf(AUTO_BROADCASTJOIN_THRESHOLD.key -> s"$autoBroadcastJoinThreshold") { + val correctAnswer = if (autoBroadcastJoinThreshold < 0) { + y.select("y.b".attr).groupBy("y.b".attr)("y.b".attr) + } else { + Aggregate(query.child.output, query.child.output, query.child) + } + comparePlans(Optimize.execute(query.analyze), correctAnswer.analyze) + } + } + } + + test("SPARK-34808: Should not remove left join if select 2 join sides") { + val x = testRelation.subquery('x) + val y = testRelation.subquery('y) + val query = Distinct(x.join(y, RightOuter, Some("x.a".attr === "y.a".attr)) + .select("x.b".attr, "y.c".attr)) + + Seq(-1, 10000).foreach { autoBroadcastJoinThreshold => + withSQLConf(AUTO_BROADCASTJOIN_THRESHOLD.key -> s"$autoBroadcastJoinThreshold") { + val correctAnswer = Aggregate(query.child.output, query.child.output, query.child) + comparePlans(Optimize.execute(query.analyze), correctAnswer.analyze) + } + } + } + + test("SPARK-34808: EliminateOuterJoin must before RemoveRepetitionFromGroupExpressions") { Review comment: why? -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org