dongjoon-hyun opened a new pull request, #60794:
URL: https://github.com/apache/spark/pull/60794
### What changes were proposed in this pull request?
This PR makes the analyzer pick the sort-merge as-of join for a DataFrame
as-of join whose left side is streaming, regardless of the internal
`spark.sql.join.sortMergeAsOfJoin.enabled` (default `false`).
- `AsOfJoinMatchConditionResolution.materializeDataFrame` now selects
sort-merge when `SQLConf.get.sortMergeAsOfJoinEnabled || join.left.isStreaming`.
- The doc of `spark.sql.join.sortMergeAsOfJoin.enabled` says so.
Batch DataFrame as-of joins and SQL `ASOF JOIN` are unchanged.
### Why are the changes needed?
SPARK-59698 allows stream-static as-of joins: each streaming row is matched
against the static snapshot. SQL `ASOF JOIN` works because it always uses the
stateless sort-merge operator. A DataFrame as-of join (`Dataset.joinAsOf`,
PySpark `DataFrame._joinAsOf` and Spark Connect `AsOfJoin`) uses
`RewriteAsOfJoin` by default instead. That rule turns the join into a
correlated scalar subquery. Decorrelation then aggregates the distinct left
values and joins the result back to the left side. On a streaming left side
these become a streaming aggregation and a stream-stream left outer join, so
every such query fails at its first micro-batch.
```scala
// `stream` is a MemoryStream (t, k), `static` is a static DataFrame (bt,
bk, v).
stream.joinAsOf(static, stream("t"), static("bt"), stream("k") ===
static("bk"),
"inner", null, true, "backward")
```
- Append output mode: `[UNSUPPORTED_STREAMING_OPERATOR_WITHOUT_WATERMARK]
Append output mode not supported for aggregations on streaming
DataFrames/DataSets without watermark.`
- Update output mode, even for an inner as-of join: `requirement failed:
Update output mode is not supported for stream-stream LeftOuter join`
It fails the same way for inner and left joins, for all three directions,
with a tolerance and with `usingColumns`. With
`spark.sql.join.sortMergeAsOfJoin.enabled=true`, each of these queries returns
the same rows as the batch join over all of its input rows.
Apache Spark 4.3.0
([v4.3.0](https://github.com/apache/spark/releases/tag/v4.3.0), 2026-10-27) has
the same failures with the default configuration.
### Does this PR introduce _any_ user-facing change?
Yes. A DataFrame as-of join with a streaming left side now runs instead of
failing at the first micro-batch. Its keys now go through the checks of the
sort-merge path, for example `AS_OF_JOIN.KEY_REFERENCE` for a key that does not
reference its own side. With the default configuration, such queries already
failed at the first micro-batch before this PR.
### How was this patch tested?
Pass the CIs with the newly added test cases in `StreamingAsOfJoinSuite`
(inner and left). Without this fix, both fail with
`UNSUPPORTED_STREAMING_OPERATOR_WITHOUT_WATERMARK`.
```
$ build/sbt "sql/testOnly
org.apache.spark.sql.streaming.StreamingAsOfJoinSuite
org.apache.spark.sql.DataFrameAsOfJoinSuite
org.apache.spark.sql.SortMergeAsOfJoinSuite"
$ build/sbt "catalyst/testOnly
org.apache.spark.sql.catalyst.optimizer.RewriteAsOfJoinSuite
org.apache.spark.sql.catalyst.analysis.UnsupportedOperationsSuite"
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
--
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]