ulysses-you commented on code in PR #60118:
URL: https://github.com/apache/spark/pull/60118#discussion_r4509219670


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/joins/FullOuterJoinPartitioningSuite.scala:
##########
@@ -0,0 +1,485 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.joins
+
+import org.apache.spark.sql.{DataFrame, QueryTest, Row}
+import org.apache.spark.sql.catalyst.expressions.{Coalesce, Literal}
+import org.apache.spark.sql.catalyst.plans.FullOuter
+import org.apache.spark.sql.catalyst.plans.physical._
+import org.apache.spark.sql.execution.SparkPlan
+import org.apache.spark.sql.execution.adaptive.{AdaptiveSparkPlanHelper, 
AQEShuffleReadExec}
+import org.apache.spark.sql.execution.exchange.ShuffleExchangeExec
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types.LongType
+
+class FullOuterJoinPartitioningSuite
+  extends QueryTest with SharedSparkSession with AdaptiveSparkPlanHelper {
+
+  private val numShufflePartitions = 5
+
+  private val baseConfs = Seq(
+    SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+    SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false",
+    SQLConf.SHUFFLE_PARTITIONS.key -> numShufflePartitions.toString)
+
+  private val usingGroupBy =
+    "SELECT k, count(*), sum(va), sum(vb) FROM a FULL OUTER JOIN b USING (k) 
GROUP BY k"
+
+  private val aggregated = "(SELECT k, count(*) AS cnt FROM a GROUP BY k) x"
+
+  /** A FULL OUTER join of a strict hash side and a null-aware side, in both 
orders. */
+  private val mixedJoins = Seq(
+    s"$aggregated FULL OUTER JOIN b ON x.k = b.k" -> "coalesce(x.k, b.k)",
+    s"b FULL OUTER JOIN $aggregated ON b.k = x.k" -> "coalesce(b.k, x.k)")
+
+  /**
+   * AQE coalescing that still leaves several partitions, so misplaced rows 
can show. The target
+   * size is far above the data, so the reducer cap alone draws the 
boundaries: every 3 of the 10
+   * reducers, whatever the shuffled bytes are.
+   */
+  private val aqeCoalescing = Seq(
+    SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+    SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+    SQLConf.COALESCE_PARTITIONS_PARALLELISM_FIRST.key -> "false",
+    SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "64MB",
+    SQLConf.COALESCE_PARTITIONS_MAX_REDUCER_PARTITIONS_PER_TASK.key -> "3",
+    SQLConf.SHUFFLE_PARTITIONS.key -> "10")
+
+  private def assertCoalescedToSeveralPartitions(plan: SparkPlan): Unit = {
+    val reads = collect(plan) { case r: AQEShuffleReadExec => r }
+    assert(reads.nonEmpty, plan)
+    assert(reads.forall(r => (2 to 
4).contains(r.outputPartitioning.numPartitions)), plan)
+  }
+
+  override def beforeAll(): Unit = {
+    super.beforeAll()
+    // Nullable keys with NULLs, overlapping key ranges, and duplicate keys on 
every side.
+    spark.range(0, 30)
+      .selectExpr("IF(id % 7 = 0, NULL, id % 10) AS k", "id % 3 AS k2", "id AS 
va")
+      .createOrReplaceTempView("a")
+    spark.range(0, 30)
+      .selectExpr("IF(id % 5 = 0, NULL, id % 10 + 5) AS k", "id % 3 AS k2", 
"id AS vb")
+      .createOrReplaceTempView("b")
+    spark.range(0, 30)
+      .selectExpr("IF(id % 4 = 0, NULL, id % 10 + 8) AS k", "id % 3 AS k2", 
"id AS vc")
+      .createOrReplaceTempView("c")
+  }
+
+  override def afterAll(): Unit = {
+    try {
+      Seq("a", "b", "c").foreach(spark.catalog.dropTempView)
+    } finally {
+      super.afterAll()
+    }
+  }
+
+  private def numShuffles(plan: SparkPlan): Int =
+    collect(plan) { case s: ShuffleExchangeExec => s }.size
+
+  private def fullOuterJoins(plan: SparkPlan): Seq[ShuffledJoin] =
+    collect(plan) { case j: ShuffledJoin if j.joinType == FullOuter => j }
+
+  /** The members of a reported partitioning, each over the coalesced join 
keys. */
+  private def members(partitioning: Partitioning): Seq[Partitioning] = {
+    val ps = PartitioningCollection.flatten(partitioning)
+    ps.foreach {
+      case h: HashPartitioningLike =>
+        assert(h.expressions.forall(_.isInstanceOf[Coalesce]), partitioning)
+      case other => fail(s"Unexpected output partitioning: $other")
+    }
+    ps
+  }
+
+  private def firstFullOuterJoin(df: DataFrame): ShuffledJoin = {
+    val joins = fullOuterJoins(df.queryExecution.executedPlan)
+    assert(joins.nonEmpty, df.queryExecution.executedPlan)
+    joins.head
+  }
+
+  private def sortedRows(df: DataFrame): Seq[String] = 
df.collect().toSeq.map(_.toString).sorted
+
+  /**
+   * Runs `query` under `confs`, asserts the answer equals the one from a 
single shuffle partition,
+   * where no placement can go wrong, and returns the number of shuffles.
+   */
+  private def compare(query: String, confs: (String, String)*): Int = {
+    val expected = withSQLConf(baseConfs ++ confs ++ Seq(
+        SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false",
+        SQLConf.SHUFFLE_PARTITIONS.key -> "1"): _*) {
+      sortedRows(sql(query))
+    }
+    withSQLConf(baseConfs ++ confs: _*) {
+      val df = sql(query)
+      assert(sortedRows(df) == expected, query)
+      numShuffles(df.queryExecution.executedPlan)
+    }
+  }
+
+  test("USING join followed by GROUP BY on the merged key does not shuffle 
again") {
+    val query = usingGroupBy
+    assert(compare(query) == 2)
+
+    withSQLConf(baseConfs: _*) {
+      val ps = members(firstFullOuterJoin(sql(query)).outputPartitioning)
+      assert(ps.size == 2)
+      assert(ps.forall {
+        case HashPartitioning(Seq(_), `numShufflePartitions`) => true
+        case _ => false
+      })
+      // A single NULL group: the NULL-keyed rows of both sides are co-located.
+      checkAnswer(
+        sql(s"SELECT count(*) FROM ($query) WHERE k IS NULL"),
+        Row(1))
+    }
+  }
+
+  test("GROUP BY an explicit COALESCE of the join keys does not shuffle 
again") {
+    def query(merged: String): String =
+      s"""SELECT c, count(*), sum(va), sum(vb) FROM (
+         |  SELECT $merged AS c, va, vb FROM a FULL OUTER JOIN b ON a.k = b.k
+         |) GROUP BY c""".stripMargin
+    assert(compare(query("coalesce(a.k, b.k)")) == 2)
+    assert(compare(query("coalesce(b.k, a.k)")) == 2)
+  }
+
+  test("a downstream join on the reversed order does not shuffle the join 
output again") {
+    def query(merged: String): String =
+      s"""SELECT * FROM (
+         |  SELECT $merged AS m, va, vb FROM a FULL OUTER JOIN b ON a.k = b.k
+         |) x FULL OUTER JOIN c ON x.m = c.k""".stripMargin
+    assert(compare(query("coalesce(a.k, b.k)")) == 3)
+    assert(compare(query("coalesce(b.k, a.k)")) == 3)
+  }
+
+  test("multi-column keys report the two uniform orders only") {
+    val join = "a FULL OUTER JOIN b ON a.k = b.k AND a.k2 = b.k2"
+    def query(k: String, k2: String): String =
+      s"SELECT $k AS c, $k2 AS c2, count(*) FROM $join GROUP BY 1, 2"
+    val (lk, rk, lk2, rk2) = ("coalesce(a.k, b.k)", "coalesce(b.k, a.k)",
+      "coalesce(a.k2, b.k2)", "coalesce(b.k2, a.k2)")
+    Seq(query(lk, lk2), query(rk, rk2)).foreach { q =>
+      assert(compare(q) == 2, q)
+    }
+    // A mixed order is not reported, so the aggregate shuffles again.
+    Seq(query(lk, rk2), query(rk, lk2)).foreach { q =>
+      assert(compare(q) == 3, q)
+    }
+    withSQLConf(baseConfs: _*) {

Review Comment:
   Thanks @dongjoon-hyun! Added `fullOuterJoinOf` in 7dd9f36cbdc and used it in 
those blocks. The remaining `withSQLConf` blocks inspect an executed `df`, so 
they stay as they are.
   



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/joins/FullOuterJoinPartitioningSuite.scala:
##########
@@ -0,0 +1,485 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.joins
+
+import org.apache.spark.sql.{DataFrame, QueryTest, Row}
+import org.apache.spark.sql.catalyst.expressions.{Coalesce, Literal}
+import org.apache.spark.sql.catalyst.plans.FullOuter
+import org.apache.spark.sql.catalyst.plans.physical._
+import org.apache.spark.sql.execution.SparkPlan
+import org.apache.spark.sql.execution.adaptive.{AdaptiveSparkPlanHelper, 
AQEShuffleReadExec}
+import org.apache.spark.sql.execution.exchange.ShuffleExchangeExec
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types.LongType
+
+class FullOuterJoinPartitioningSuite
+  extends QueryTest with SharedSparkSession with AdaptiveSparkPlanHelper {
+
+  private val numShufflePartitions = 5
+
+  private val baseConfs = Seq(
+    SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+    SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false",
+    SQLConf.SHUFFLE_PARTITIONS.key -> numShufflePartitions.toString)
+
+  private val usingGroupBy =
+    "SELECT k, count(*), sum(va), sum(vb) FROM a FULL OUTER JOIN b USING (k) 
GROUP BY k"
+
+  private val aggregated = "(SELECT k, count(*) AS cnt FROM a GROUP BY k) x"
+
+  /** A FULL OUTER join of a strict hash side and a null-aware side, in both 
orders. */
+  private val mixedJoins = Seq(
+    s"$aggregated FULL OUTER JOIN b ON x.k = b.k" -> "coalesce(x.k, b.k)",
+    s"b FULL OUTER JOIN $aggregated ON b.k = x.k" -> "coalesce(b.k, x.k)")
+
+  /**
+   * AQE coalescing that still leaves several partitions, so misplaced rows 
can show. The target
+   * size is far above the data, so the reducer cap alone draws the 
boundaries: every 3 of the 10
+   * reducers, whatever the shuffled bytes are.
+   */
+  private val aqeCoalescing = Seq(
+    SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+    SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+    SQLConf.COALESCE_PARTITIONS_PARALLELISM_FIRST.key -> "false",
+    SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "64MB",
+    SQLConf.COALESCE_PARTITIONS_MAX_REDUCER_PARTITIONS_PER_TASK.key -> "3",
+    SQLConf.SHUFFLE_PARTITIONS.key -> "10")
+
+  private def assertCoalescedToSeveralPartitions(plan: SparkPlan): Unit = {
+    val reads = collect(plan) { case r: AQEShuffleReadExec => r }
+    assert(reads.nonEmpty, plan)
+    assert(reads.forall(r => (2 to 
4).contains(r.outputPartitioning.numPartitions)), plan)
+  }
+
+  override def beforeAll(): Unit = {
+    super.beforeAll()
+    // Nullable keys with NULLs, overlapping key ranges, and duplicate keys on 
every side.
+    spark.range(0, 30)
+      .selectExpr("IF(id % 7 = 0, NULL, id % 10) AS k", "id % 3 AS k2", "id AS 
va")
+      .createOrReplaceTempView("a")
+    spark.range(0, 30)
+      .selectExpr("IF(id % 5 = 0, NULL, id % 10 + 5) AS k", "id % 3 AS k2", 
"id AS vb")
+      .createOrReplaceTempView("b")
+    spark.range(0, 30)
+      .selectExpr("IF(id % 4 = 0, NULL, id % 10 + 8) AS k", "id % 3 AS k2", 
"id AS vc")
+      .createOrReplaceTempView("c")
+  }
+
+  override def afterAll(): Unit = {
+    try {
+      Seq("a", "b", "c").foreach(spark.catalog.dropTempView)
+    } finally {
+      super.afterAll()
+    }
+  }
+
+  private def numShuffles(plan: SparkPlan): Int =
+    collect(plan) { case s: ShuffleExchangeExec => s }.size
+
+  private def fullOuterJoins(plan: SparkPlan): Seq[ShuffledJoin] =
+    collect(plan) { case j: ShuffledJoin if j.joinType == FullOuter => j }
+
+  /** The members of a reported partitioning, each over the coalesced join 
keys. */
+  private def members(partitioning: Partitioning): Seq[Partitioning] = {
+    val ps = PartitioningCollection.flatten(partitioning)
+    ps.foreach {
+      case h: HashPartitioningLike =>
+        assert(h.expressions.forall(_.isInstanceOf[Coalesce]), partitioning)
+      case other => fail(s"Unexpected output partitioning: $other")
+    }
+    ps
+  }
+
+  private def firstFullOuterJoin(df: DataFrame): ShuffledJoin = {
+    val joins = fullOuterJoins(df.queryExecution.executedPlan)
+    assert(joins.nonEmpty, df.queryExecution.executedPlan)
+    joins.head
+  }
+
+  private def sortedRows(df: DataFrame): Seq[String] = 
df.collect().toSeq.map(_.toString).sorted
+
+  /**
+   * Runs `query` under `confs`, asserts the answer equals the one from a 
single shuffle partition,
+   * where no placement can go wrong, and returns the number of shuffles.
+   */
+  private def compare(query: String, confs: (String, String)*): Int = {
+    val expected = withSQLConf(baseConfs ++ confs ++ Seq(
+        SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false",
+        SQLConf.SHUFFLE_PARTITIONS.key -> "1"): _*) {
+      sortedRows(sql(query))
+    }
+    withSQLConf(baseConfs ++ confs: _*) {
+      val df = sql(query)
+      assert(sortedRows(df) == expected, query)
+      numShuffles(df.queryExecution.executedPlan)
+    }
+  }
+
+  test("USING join followed by GROUP BY on the merged key does not shuffle 
again") {
+    val query = usingGroupBy
+    assert(compare(query) == 2)
+
+    withSQLConf(baseConfs: _*) {
+      val ps = members(firstFullOuterJoin(sql(query)).outputPartitioning)
+      assert(ps.size == 2)
+      assert(ps.forall {
+        case HashPartitioning(Seq(_), `numShufflePartitions`) => true
+        case _ => false
+      })
+      // A single NULL group: the NULL-keyed rows of both sides are co-located.
+      checkAnswer(

Review Comment:
   Thanks @dongjoon-hyun! Removed both in 7dd9f36cbdc; the comment now sits on 
the `compare` line.
   



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/joins/FullOuterJoinPartitioningSuite.scala:
##########
@@ -0,0 +1,485 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.joins
+
+import org.apache.spark.sql.{DataFrame, QueryTest, Row}
+import org.apache.spark.sql.catalyst.expressions.{Coalesce, Literal}
+import org.apache.spark.sql.catalyst.plans.FullOuter
+import org.apache.spark.sql.catalyst.plans.physical._
+import org.apache.spark.sql.execution.SparkPlan
+import org.apache.spark.sql.execution.adaptive.{AdaptiveSparkPlanHelper, 
AQEShuffleReadExec}
+import org.apache.spark.sql.execution.exchange.ShuffleExchangeExec
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types.LongType
+
+class FullOuterJoinPartitioningSuite
+  extends QueryTest with SharedSparkSession with AdaptiveSparkPlanHelper {
+
+  private val numShufflePartitions = 5
+
+  private val baseConfs = Seq(
+    SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+    SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false",
+    SQLConf.SHUFFLE_PARTITIONS.key -> numShufflePartitions.toString)
+
+  private val usingGroupBy =
+    "SELECT k, count(*), sum(va), sum(vb) FROM a FULL OUTER JOIN b USING (k) 
GROUP BY k"
+
+  private val aggregated = "(SELECT k, count(*) AS cnt FROM a GROUP BY k) x"
+
+  /** A FULL OUTER join of a strict hash side and a null-aware side, in both 
orders. */
+  private val mixedJoins = Seq(
+    s"$aggregated FULL OUTER JOIN b ON x.k = b.k" -> "coalesce(x.k, b.k)",
+    s"b FULL OUTER JOIN $aggregated ON b.k = x.k" -> "coalesce(b.k, x.k)")
+
+  /**
+   * AQE coalescing that still leaves several partitions, so misplaced rows 
can show. The target
+   * size is far above the data, so the reducer cap alone draws the 
boundaries: every 3 of the 10
+   * reducers, whatever the shuffled bytes are.
+   */
+  private val aqeCoalescing = Seq(
+    SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+    SQLConf.COALESCE_PARTITIONS_ENABLED.key -> "true",
+    SQLConf.COALESCE_PARTITIONS_PARALLELISM_FIRST.key -> "false",
+    SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "64MB",
+    SQLConf.COALESCE_PARTITIONS_MAX_REDUCER_PARTITIONS_PER_TASK.key -> "3",
+    SQLConf.SHUFFLE_PARTITIONS.key -> "10")
+
+  private def assertCoalescedToSeveralPartitions(plan: SparkPlan): Unit = {
+    val reads = collect(plan) { case r: AQEShuffleReadExec => r }
+    assert(reads.nonEmpty, plan)
+    assert(reads.forall(r => (2 to 
4).contains(r.outputPartitioning.numPartitions)), plan)
+  }
+
+  override def beforeAll(): Unit = {
+    super.beforeAll()
+    // Nullable keys with NULLs, overlapping key ranges, and duplicate keys on 
every side.
+    spark.range(0, 30)
+      .selectExpr("IF(id % 7 = 0, NULL, id % 10) AS k", "id % 3 AS k2", "id AS 
va")
+      .createOrReplaceTempView("a")
+    spark.range(0, 30)
+      .selectExpr("IF(id % 5 = 0, NULL, id % 10 + 5) AS k", "id % 3 AS k2", 
"id AS vb")
+      .createOrReplaceTempView("b")
+    spark.range(0, 30)
+      .selectExpr("IF(id % 4 = 0, NULL, id % 10 + 8) AS k", "id % 3 AS k2", 
"id AS vc")
+      .createOrReplaceTempView("c")
+  }
+
+  override def afterAll(): Unit = {
+    try {
+      Seq("a", "b", "c").foreach(spark.catalog.dropTempView)
+    } finally {
+      super.afterAll()
+    }
+  }
+
+  private def numShuffles(plan: SparkPlan): Int =
+    collect(plan) { case s: ShuffleExchangeExec => s }.size
+
+  private def fullOuterJoins(plan: SparkPlan): Seq[ShuffledJoin] =
+    collect(plan) { case j: ShuffledJoin if j.joinType == FullOuter => j }
+
+  /** The members of a reported partitioning, each over the coalesced join 
keys. */
+  private def members(partitioning: Partitioning): Seq[Partitioning] = {
+    val ps = PartitioningCollection.flatten(partitioning)
+    ps.foreach {
+      case h: HashPartitioningLike =>
+        assert(h.expressions.forall(_.isInstanceOf[Coalesce]), partitioning)
+      case other => fail(s"Unexpected output partitioning: $other")
+    }
+    ps
+  }
+
+  private def firstFullOuterJoin(df: DataFrame): ShuffledJoin = {
+    val joins = fullOuterJoins(df.queryExecution.executedPlan)
+    assert(joins.nonEmpty, df.queryExecution.executedPlan)
+    joins.head
+  }
+
+  private def sortedRows(df: DataFrame): Seq[String] = 
df.collect().toSeq.map(_.toString).sorted
+
+  /**
+   * Runs `query` under `confs`, asserts the answer equals the one from a 
single shuffle partition,
+   * where no placement can go wrong, and returns the number of shuffles.
+   */
+  private def compare(query: String, confs: (String, String)*): Int = {
+    val expected = withSQLConf(baseConfs ++ confs ++ Seq(
+        SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false",
+        SQLConf.SHUFFLE_PARTITIONS.key -> "1"): _*) {
+      sortedRows(sql(query))
+    }
+    withSQLConf(baseConfs ++ confs: _*) {
+      val df = sql(query)
+      assert(sortedRows(df) == expected, query)
+      numShuffles(df.queryExecution.executedPlan)
+    }
+  }
+
+  test("USING join followed by GROUP BY on the merged key does not shuffle 
again") {
+    val query = usingGroupBy
+    assert(compare(query) == 2)
+
+    withSQLConf(baseConfs: _*) {
+      val ps = members(firstFullOuterJoin(sql(query)).outputPartitioning)
+      assert(ps.size == 2)
+      assert(ps.forall {
+        case HashPartitioning(Seq(_), `numShufflePartitions`) => true
+        case _ => false
+      })
+      // A single NULL group: the NULL-keyed rows of both sides are co-located.
+      checkAnswer(
+        sql(s"SELECT count(*) FROM ($query) WHERE k IS NULL"),
+        Row(1))
+    }
+  }
+
+  test("GROUP BY an explicit COALESCE of the join keys does not shuffle 
again") {
+    def query(merged: String): String =
+      s"""SELECT c, count(*), sum(va), sum(vb) FROM (
+         |  SELECT $merged AS c, va, vb FROM a FULL OUTER JOIN b ON a.k = b.k
+         |) GROUP BY c""".stripMargin
+    assert(compare(query("coalesce(a.k, b.k)")) == 2)
+    assert(compare(query("coalesce(b.k, a.k)")) == 2)
+  }
+
+  test("a downstream join on the reversed order does not shuffle the join 
output again") {

Review Comment:
   Thanks @dongjoon-hyun! Renamed in 7dd9f36cbdc.
   



-- 
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]

Reply via email to