HeartSaVioR commented on PR #59909: URL: https://github.com/apache/spark/pull/59909#issuecomment-6752997732
> [!NOTE] > **DISCLAIMER:** This comment was written by an LLM, Claude Opus 5.5 (`claude-opus-5-5`, 1M context), posting on behalf of @HeartSaVioR. Thanks for the review. All inline points are addressed in [e3212ca903a](https://github.com/apache/spark/commit/e3212ca903ab0d829feab6150bda53ea5ad88cfa), with a reply on each comment. On the two design questions: **A separate node instead of a marked `Join`.** The [design doc](https://gist.github.com/HeartSaVioR/0143cdaad3079d1455be8004ee401ec4) now records this trade-off as P8, in section 6. In short: - **The two joins differ in ways the optimizer cares about.** A lookup join's right side must stay a table read by lookups, and its stream side must stay on the left. So it must never be reordered, swapped, turned into a cross join or planned by `JoinSelection`. Optimizations and hints written for `Join` do not carry over: strategy hints conflict with it, for example. - **Diverging early is safer than diverging late.** With a marked `Join`, every existing and future `Join` rule applies by default. Each one that can break the points above would need its own guard, and a missing guard silently gives a wrong plan. With a separate node, a missing rule only costs an optimization. - **Structured Streaming learned this with stateful operators.** They diverged from their batch counterparts only at physical planning, picked up optimizations written for the batch operators, and became fragile. **Errors after `start()`.** Agreed: they should fail when the query starts. This round does that in two parts. Please check whether the second is more machinery than you had in mind. - **`MISSING_JOIN_CONDITION`** is now reported during analysis of the streaming write, which is complete when the query starts ([e3212ca903a](https://github.com/apache/spark/commit/e3212ca903ab0d829feab6150bda53ea5ad88cfa)). In #60198, a lookup key may also come from a WHERE clause, as for an ordinary join, so there the startup check reports a join that is still without a condition. - **The other planning errors** need the optimizer, because simplification and predicate pushdown can add lookup conditions. So #59910 adds a dry run in `StreamingQueryManager.createQuery`, in the thread that calls `start()` ([ff67010628f](https://github.com/apache/spark/commit/ff67010628ff2215bc180eb23c1d60ae7e4181cc)): - **It optimizes a throwaway copy of the query, and discards the result.** Nothing from it is reused: each micro-batch still plans from the analyzed plan, as before. - The copy keeps only the lookup sides. The other static parts become placeholders, so their scans are neither built nor planned at the start. - It uses the optimizer and the configuration of the micro-batches, including the values that the offset log pins for a restarted query. - Only lookup-specific planning errors fail `start()`. An error that an ordinary join would also raise at the first micro-batch stays there, and so do errors raised while the join runs. - **Cost:** about one optimizer run, 3 to 7 ms in local tests, plus one round of connector planning calls, which every micro-batch already makes. Only a query with a lookup join pays it. The new check is about 100 lines, of which about 50 are code, plus a one-line hook in `createQuery`. An internal config turns it off. - If this is more than you meant, we can keep only the analysis check above, and leave the other errors to the first micro-batch, as for an ordinary join. - **A bug this uncovered:** the startup column pruning of SPARK-60734 hid the lookup side, so with `spark.sql.streaming.v2ColumnPruning.enabled`, a micro-batch could fail with `STREAMING_SCAN_MISSING_COLUMNS`. Its placeholders, which the new check shares, now keep the lookup sides. The design doc records these as E5 and O4. -- 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]
