dwsmith1983 commented on code in PR #6785:
URL: https://github.com/apache/datafusion-comet/pull/6785#discussion_r4707367703
##########
spark/src/test/scala/org/apache/comet/exec/CometJoinSuite.scala:
##########
@@ -2999,6 +3614,125 @@ class CometJoinSuite extends CometTestBase {
}
}
+ test("an inner hash join over a checkpointed streamed side declares no
order") {
+ // Comet cannot check the checkpoint's order, so it declares none, and the
inner join keeps its
+ // probe rows in place without one, so it stays native.
+ withOrderedCheckpoint { streamed =>
+ val build = spark.range(10).selectExpr("id * 10 AS k", "id AS w")
+ val order =
+ (0 to 1).map(i => SortOrder(BoundReference(i, LongType, nullable =
true), Ascending))
+ for (hint <- Seq("shuffle_hash", "broadcast")) {
+ def df: DataFrame = streamed
+ .join(build.hint(hint), streamed("k") === build("k"))
+ .select(streamed("k"), streamed("v"), build("w"))
+ .sortWithinPartitions("k", "v")
+ val (_, plan) = checkSparkAnswer(df)
+ val declared = collect(plan) {
+ case j: CometHashJoinExec =>
j.nativeOp.getHashJoin.getStreamedSortOrdersCount
+ case j: CometBroadcastHashJoinExec =>
j.nativeOp.getHashJoin.getStreamedSortOrdersCount
+ }
+ assert(declared == Seq(0), s"$hint\n$plan")
+ assert(
+ collect(plan) { case s @ (_: CometSortExec | _: SortExec) => s
}.isEmpty,
+ s"$hint\n$plan")
+ assert(partitionsInOrder(df, order: _*), s"$hint\n$plan")
+ }
+ }
+ }
+
+ test("a native window above an inner hash join over a checkpointed streamed
side runs") {
+ // Spark drops the window's sort for the checkpoint's order, which the
join reports, but Comet
+ // cannot check that order, so the join declares none and the native
window sorts its input.
+ withOrderedCheckpoint { streamed =>
+ for {
+ (build, force) <- checkpointJoinBuildSides
+ window <- Seq(
+ "dense_rank() OVER (PARTITION BY k ORDER BY v)",
+ "sum(v) OVER (PARTITION BY k)")
+ } {
+ withSQLConf(CometConf.COMET_FORCE_SHJ.key -> force.toString) {
+ def df: DataFrame = streamed
+ .join(build, $"k" === $"id")
+ .selectExpr("k", "v", s"$window AS r")
+ val plan = df.queryExecution.executedPlan
+ val context = s"force=$force $window\n$plan"
+ val joins = collect(plan) {
+ case j: CometHashJoinExec => j
+ case j: CometBroadcastHashJoinExec => j
+ }
+ assert(joins.size == 1, context)
+ val windows = collect(plan) { case w: CometWindowExec => w }
+ assert(
+
windows.map(_.nativeOp.getWindow.getUnverifiedInputSortOrdersCount) == Seq(2),
+ context)
+ assert(
+ collect(plan) { case s @ (_: CometSortExec | _: SortExec) => s
}.isEmpty,
+ context)
+ sameRowsAsSpark(df)
+ }
+ }
+ }
+ }
+
+ test("a native window group limit above an inner hash join over a checkpoint
ranks it") {
+ // The native limit declares the order Spark requires of its input without
checking it, which
+ // holds for the checkpoint's rows.
+ withOrderedCheckpoint { streamed =>
+ for ((build, force) <- checkpointJoinBuildSides) {
+ withSQLConf(CometConf.COMET_FORCE_SHJ.key -> force.toString) {
+ def df: DataFrame = streamed
+ .join(build, $"k" === $"id")
+ .selectExpr("k", "v", "rank() OVER (PARTITION BY k ORDER BY v) AS
rk")
+ .where("rk <= 2")
+ val plan = df.queryExecution.executedPlan
+ val context = s"force=$force\n$plan"
+ assert(collect(plan) { case l: CometWindowGroupLimitExec => l
}.nonEmpty, context)
+ assert(collect(plan) { case w: CometWindowExec => w }.size == 1,
context)
+ assert(
+ collect(plan) { case s @ (_: CometSortExec | _: SortExec) => s
}.isEmpty,
+ context)
+ sameRowsAsSpark(df)
+ }
+ }
+ }
+ }
+
+ test("a native window over an outer hash join that may move rows restores
the whole order") {
Review Comment:
> This passes for me with the native window's sort restoration disabled,
since it's all one native plan. Could the name say no sort is needed here?
Renamed in cb3c480e8 to "a native window over an outer hash join in the same
native plan needs no sort". The comment now says why: the join and both windows
share one native plan, where DataFusion sees the order and adds no sort. The
native side of that is pinned by
`window_sorts_by_the_unverified_order_it_was_sent` in `window_input_order.rs`.
With the restoration disabled, "a native window above an inner hash join over a
checkpointed streamed side runs" and five checkpoint tests in
`CometWindowExecSuite` fail, so it is still covered.
--
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]