gengliangwang commented on code in PR #55629:
URL: https://github.com/apache/spark/pull/55629#discussion_r3185614384
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -657,6 +657,34 @@ trait CheckAnalysis extends LookupCatalog with
QueryErrorsBase with PlanToString
messageParameters = Map.empty)
}
+ // Reject streaming inputs early. The optimizer rewrite is built
around an
+ // unconditioned cross-product fed into a global `Aggregate` keyed
by a per-row
+ // identifier (`__qid`). That shape doesn't compose cleanly with
structured-streaming
+ // semantics: a stateful aggregate keyed by a freshly-generated
identifier accumulates
+ // state indefinitely (every batch creates new keys, old keys never
match again) and a
+ // cross-product against a streaming right side has no bounded state
model today.
+ // Failing at analysis time is clearer than letting either fail at
runtime. Streaming
+ // support is tracked as a follow-up; resolving it likely comes from
a different
+ // grouping strategy or a dedicated physical operator.
+ case j: NearestByJoin if j.isStreaming =>
+ j.failAnalysis(
+ errorClass = "NEAREST_BY_JOIN.STREAMING_NOT_SUPPORTED",
+ messageParameters = Map.empty)
Review Comment:
Removing the `CheckCartesianProducts` skip was the right call, but the
user-visible failure now leaks rewrite internals. With
`spark.sql.crossJoin.enabled = false`, a `JOIN ... APPROX NEAREST 1 BY ...`
query fails with `_LEGACY_ERROR_TEMP_1211`:
> Detected implicit cartesian product for **LEFT OUTER** join between
logical plans
> `Project [... uuid(Some(<random>)) AS __qid#x] +- ...`
> and `...`
> Join condition is missing or trivial.
> Either: use the CROSS JOIN syntax ..., or: enable implicit cartesian
products by setting `spark.sql.crossJoin.enabled=true`.
The user wrote `JOIN ... APPROX NEAREST 1 BY ...` and gets back: `LEFT
OUTER` (a join type they didn't write — the rewrite's synthetic outer), `__qid`
and `uuid(Some(...))` (purely internal), and "use the CROSS JOIN syntax" advice
that doesn't apply to NEAREST BY. Only the conf-flip suggestion is actionable.
The new test golden output
(`sql/core/src/test/resources/sql-tests/results/join-nearest-by.sql.out`,
around the new `_LEGACY_ERROR_TEMP_1211` block) makes this concrete — that's
exactly what the user sees.
Could this be gated here, alongside `STREAMING_NOT_SUPPORTED`, with a
NEAREST BY-specific arm — e.g.:
```scala
case j: NearestByJoin if !conf.crossJoinEnabled =>
j.failAnalysis(
errorClass = "NEAREST_BY_JOIN.CROSS_JOIN_NOT_ENABLED",
messageParameters = Map.empty)
```
plus a new sub-condition explaining that NEAREST BY is implemented as a
bounded cross-product and pointing the user at `spark.sql.crossJoin.enabled =
true`. Since `CheckAnalysis` runs before the optimizer rewrite, the synthetic
plan whose internals leak into `_LEGACY_ERROR_TEMP_1211` would never be
produced for this case.
--
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]