Repository navigation
[data] Fix join schema validation for asymmetric and multi-key joins - #67505
Merged
owenowenisme merged 2 commits intoOct 30, 2026
Merged
Conversation
Signed-off-by: Yin-1022 <[email protected]>
Contributor
There was a problem hiding this comment.
Code Review
This pull request corrects schema validation during join operations by ensuring that key column types are resolved and compared in the exact order of the specified join keys. It fixes a bug where the left and right key column names were swapped when retrieving column types, refactors _get_key_column_types to maintain key order, and adds corresponding unit tests for asymmetric join keys and multi-key ordering. There are no review comments to address, and we have no further feedback to provide.
hikaru-212
reviewed
Oct 29, 2026
Signed-off-by: Yin-1022 <[email protected]>
owenowenisme
approved these changes
Oct 30, 2026
|
|
||
| right_op_key_cols = _get_key_column_types( | ||
| right_op_schema, left_key_column_names | ||
| right_op_schema, right_key_column_names |
owenowenisme
enabled auto-merge (squash)
October 30, 2026 18:50
sampan-s-nayak
pushed a commit
that referenced
this pull request
Nov 13, 2026
…rom it (#67590) ## Description `Dataset.join` only takes hash keys through `on`/`right_on`, so a second equality between the two sides can only be written as a `filter` above the join. TPC-H q5 does exactly that, `HashJoin(l_suppkey = s_suppkey)` followed by `Filter(c_nationkey = s_nationkey)`, so every `l_suppkey` match is materialized before the nation check drops most of it (the issue estimates ~25x more probe matches than survive). The engine already supports composite keys; what is missing is the decomposition being automatic. - Add `condition: Expr` to `Dataset.join` and the `Join` logical operator. Column references name *input* columns (before any suffix); a name present on both sides is ambiguous and raises. `on` stays required, so a `condition` alone (theta join) is rejected, as the issue asks. - Add `ExtractEquiJoinKeys`, which splits the top-level `AND` chain of the condition: every `col(a) == col(b)` with `a` and `b` on different sides becomes a condition key pair (either operand order, pairs already in `on`/`right_on` not repeated). Condition keys are hashed on and matched like `on` keys but not coalesced: both columns stay in the output with their own values, the same columns as `join().filter()`, and an unmatched row of an outer join has a null in the other side's column. Everything else stays on the operator as the residual condition for #66835. - `validate_schemas=True` checks the keys the join actually runs with, i.e. `on`/`right_on` plus the pairs extracted from `condition`. - A column can be a key only once per side. A `condition` equality that reuses a column already in `on`/`right_on`, or the same column twice, raises with a pointer to `filter()` instead of producing duplicate key names. - Switch the TPC-H q2 and q5 scripts from a filter above the join to `condition` (item 3 of the issue). ### TPC-H q2 / q5 evidence (sf1, single machine) Ran the release scripts' `main()` through the `Benchmark` harness against SF1 data generated with DuckDB's `dbgen` (exported with the column names and types of the `s3://ray-benchmark-data/tpch/parquet` files), and compared the output with DuckDB running the reference SQL. | | planned condition key | residual | vs. DuckDB reference | wall time | |---|---|---|---|---| | q2 | `ps_supplycost_f = min_supplycost` | none | 100 rows, identical including order | 13.5 s | | q5 | `c_nationkey = s_nationkey` | none | 5 rows, identical revenue | 11.7 s | ```mermaid flowchart LR subgraph Before B1["Join(l_suppkey = s_suppkey)"] --> B2["Filter(c_nationkey = s_nationkey)"] end subgraph After A0["Join(on, condition)"] -->|ExtractEquiJoinKeys| A1["Join(on: l_suppkey = s_suppkey, condition key: c_nationkey = s_nationkey)"] end classDef removed fill:#ffcdd2,stroke:#c62828,color:#000 classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000 class B2 removed class A0,A1 added ``` ### Subsystems logical planning / query optimization (behavioral change), API (`Dataset.join` parameter), physical planning (passes condition keys, rejects a leftover condition), shuffle / aggregation (join reduce matches condition keys without coalescing). ## Related issues Closes #66834 ## Additional information **Condition columns are input names.** The condition has `ON`-clause semantics: under an outer join `join(cond)` is not `join().filter(cond)`, and #66835's probe-time evaluation needs input names too. We resolve by name, not by attribute id as Spark's `ExtractEquiJoinKeys` does, so a name present on both sides is an error rather than a guess. **Where errors surface.** `Dataset.join` resolves the condition immediately when both input schemas are inferable without execution, so an unknown or ambiguous column fails at the call site. When a schema is unknown (e.g. after a row UDF) the planner reports it. `Join.infer_schema()` itself never raises; `Dataset.__repr__` calls it and expects `None` for "unknown". It does use the resolved condition keys, so `ds.schema()` is the same before and after the rewrite. **Residual.** Non-equality conjuncts stay in `Join.condition` and `plan_join_op` raises `NotImplementedError` for them. I did not rewrite them into a `Filter` above the join: that is only correct for inner joins, and #66835 replaces this check with evaluation inside the reduce task. **Interaction with #67505 and #67122.** Both merged while this was open and the branch is rebased on them. `validate_schemas=True` feeds #67505's check every matched pair. #67122's pushdown only reads the `on` keys to decide which right columns are coalesced away; condition keys are ordinary output columns to it, so the two rules don't depend on each other's order. **Execution.** The reduce joins each condition pair on a same-named temporary copy of the two columns and drops the copy afterwards, which is what leaves the originals uncoalesced. Both shuffle paths hash on `on` plus condition keys. A v2 full outer join with condition keys doesn't advertise an output partitioning, because its unmatched right rows hold nulls in the left condition columns. --------- Signed-off-by: Jie-Kai Chang <[email protected]>
1 task done
chia7712
pushed a commit
to opensource4you/readme
that referenced
this pull request
Nov 25, 2026
fellowship: 提名 Yin-1022 (ray, 2026-11) 建議等級:2 萬 - [x] 關係人宣告:提名人與被提名者無親屬、僱傭、財務、業務合作或其他可能影響公正判斷之利害關係 - 在兩個月內自己找到 8 個 Ray Data Issue 並開了 PR,其中 6 個 PR 被 Merged ([Merged PRs](https://github.com/ray-project/ray/pulls?q=is%3Apr+author%3AYin-1022+is%3Amerged+merged%3A%3C%3D2026-11-24)) - 兩個月內共 review 28 個 PR,其中 10 個提出的問題有被作者採納修正([#68402](https://github.com/ray-project/ray/pull/68402)、[#68290](https://github.com/ray-project/ray/pull/68290)、[#67524](https://github.com/ray-project/ray/pull/67524)) - 大部分 PR 都有清楚列出 Before/After 的差距,performance 相關的會附上數據 ([#67935](ray-project/ray#67935), [#68403](ray-project/ray#68403)) - 對於 Maintainer 的 Review 會清楚了解之後回覆 ([#67935 comment](ray-project/ray#67935 (comment)), [#66878 comment](ray-project/ray#66878 (comment)), [#67505 comment](ray-project/ray#67505 (comment)))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Dataset.join(..., validate_schemas=True)can mishandle join-key schema validation in two cases:on/right_onkeys are looked up against the wrong input schemas, allowing missing or incompatible join keys to pass validation.Changes
on/right_oninstead of schema column order.right_onkeys;Before / After Comparison
Before this change:
validate_schemas=Trueand fail only later during execution.ValueErrorwhen the two schemas stored join-key columns in different orders.After this change:
The new regression tests fail on
masteracross shuffle v1, shuffle v2, and disk shuffle:ValueError.The same targeted schema-validation tests pass with this change.
Related issues
Fixes #67415
Additional information
The validation change is limited to join schema checking and does not modify join execution behavior.