peter-toth commented on code in PR #60334:
URL: https://github.com/apache/spark/pull/60334#discussion_r4539688415
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/KeyGroupedPartitioningSuite.scala:
##########
@@ -4581,6 +4581,36 @@ class KeyGroupedPartitioningSuite extends
DistributionAndOrderingSuiteBase {
}
}
+ test("SPARK-60460: nested SPJ shuffles when compatible transforms share
partition values") {
+ val idCol = Array(Column.create("id", LongType))
+ createTable("pa12", idCol, Array(bucket(12, "id")))
+ createTable("pd", idCol, Array.empty)
+ createTable("pb8", idCol, Array(bucket(8, "id")))
+ // 12 is bucket 0 on pa12 and bucket 4 on pb8. The other ids make both
scans report 0-7.
+ val ids = (0L to 7L) :+ 12L
+ Seq("pa12", "pd", "pb8").foreach { t =>
+ sql(s"INSERT INTO testcat.ns.$t VALUES ${ids.map(i =>
s"($i)").mkString(", ")}")
+ }
+
+ Seq(true, false).foreach { aqe =>
+ withSQLConf(
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> aqe.toString,
+ SQLConf.V2_BUCKETING_SHUFFLE_ENABLED.key -> "true",
+ SQLConf.V2_BUCKETING_ALLOW_COMPATIBLE_TRANSFORMS.key -> "true") {
+ val df = sql(
+ """
+ |SELECT /*+ MERGE(pa12, pd, pb8) */ pa12.id, pd.id, pb8.id
Review Comment:
**Finding 1.** The test pins one of the shapes that the base gets wrong.
These all drop id 12 on the base, with AQE on and off, and return all 9 rows on
the head (`pc4` is `bucket(4, id)`, `pe12` is `bucket(12, id)`, same ids, all
joined on `id`):
| shape | base rows, shuffles | head rows, shuffles |
|---|---|---|
| `pa12 JOIN pd JOIN pb8` (this test) | 8, 1 | 9, 2 |
| `pb8 JOIN pd JOIN pa12` | 8, 1 | 9, 2 |
| `pa12 JOIN pd JOIN pb8 JOIN pc4` | 8, 2 | 9, 3 |
| `pa12 JOIN pd JOIN pe12 JOIN pb8` | 8, 1 | 9, 2 |
| `pb8 JOIN pd JOIN pa12 JOIN pe12` | 8, 1 | 9, 3 |
| `pa12 JOIN (pb8 JOIN pd)` | 8, 1 | 9, 2 |
| `pb8 JOIN (pa12 JOIN pd)` | 8, 1 | 9, 2 |
In the first five the nested join comes first. The children tie on 8
partitions, and the first one wins `maxBy`. So the best spec is the collection,
and the `(ShuffleSpecCollection(xs), _)` arm decides. In the last two the plain
scan is the best spec. There the `(_, ShuffleSpecCollection(ys))` arm decides,
which the test never reaches. Could the test loop over a few of these,
including one with the nested join on the right?
--
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]