DataFusion 55: eliminate_cross_join drops a join key that reads two tables of a cross join, and returns wrong rows — draft for upstream
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
调研方向
The repro is the Python snippet in the issue body, using datafusion-python 55.0.0 and a two-table cross join with two equality keys. Run it, then compare with DuckDB's output; the issue says the correct answer is the rows (0, 0, 10.0) and (0, 1, 20.0). The suspect is the optimizer rule eliminate_cross_join in apache/datafusion, so the fix belongs upstream rather than in this repo. Check whether PR apache/datafusion#26786 already fixes it on main before filing. Done means a clean upstream report with this repro, or a confirmed fix there.
由索引模型根据 Issue 内容生成。
描述
🌀 Claude: A wrong answer in DataFusion 55. An inner join has two equality keys, and one of them reads two tables of an earlier cross join: b.i = a.i + t.d. The optimizer rule eliminate_cross_join reorders the joins and keeps the other key, b.j = a.j, but drops this one, so the query returns every row that matches on j.
import datafusion
import pyarrow as pa
ctx = datafusion.SessionContext()
ctx.register_record_batches("x", [pa.table({"i": [0, 0, 1, 1], "j": [0, 1, 0, 1], "v": [1.0, 2.0, 10.0, 20.0]}).to_batches()])
ctx.register_record_batches("t", [pa.table({"d": [1]}).to_batches()])
q = """SELECT a.i, a.j, b.v FROM x a CROSS JOIN t
JOIN x b ON b.i = a.i + t.d AND b.j = a.j ORDER BY 1, 2, 3"""
print(ctx.sql(q).to_pylist())
- Expected, as DuckDB 1.5.6 returns:
(0, 0, 10.0)and(0, 1, 20.0). Onlya.i = 0has a row ati + 1. - Got, on DataFusion 55.0.0 (datafusion-python 55.0.0, Python 3.12, Linux x86-64): all 8 combinations of
aandbwith the samej, including(1, 0, 1.0), which no row satisfies.
The bug needs all three of:
- the cross join, written
CROSS JOIN torJOIN t ON true; the comma-join form,FROM x a, t, x b WHERE …, is correct; - a key that reads both inputs of the cross join;
- a second equality key. With
ON b.i = a.i + t.dalone, the answer is right.
EXPLAIN VERBOSE shows where it happens. After extract_equijoin_predicate, the join is Inner Join: a.i + t.d = b.i, a.j = b.j over Cross Join(a, t). After eliminate_cross_join, it is Cross Join(Inner Join: a.j = b.j (a, b), t), and the key a.i + t.d = b.i is gone from the plan.
How it was found: writing a bilinear upsampling as SQL, for an ML demo in benchmarks/ml. The upsampling cross-joins each coarse cell with a small table of taps, then joins the cell each tap reads on its latitude and longitude. DataFusion's answer was off by a factor of about 20, and DuckDB's matched PyTorch to 2e-7.
No existing issue in apache/datafusion matches. apache/datafusion#26786 (merged 2026-10-31) refactors this rule; whether it fixes this needs checking on main.
Upstream: report to apache/datafusion with the repro above. The fix is in eliminate_cross_join, where an equality key whose side reads several inputs of the flattened cross join has to stay a join filter, or be placed on the join that brings those inputs together.
- 主要语言
- Python
- 星标
- 142
- 派生
- 19
- 平均合并
- 3 天 47 分钟
- 30 天内合并 PR
- 8
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
xqlsystems/xarray-sql 的其他 Issue
-
dependencies github_actions
难度 2/5 1-3 小时 新手友好度 70/100
xqlsystems/xarray-sql#295 ·
维护者通常 3 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
xqlsystems/xarray-sql#288 ·
维护者通常 3 天内回复
-
documentation ml
难度 1/5 1-3 小时 新手友好度 85/100
xqlsystems/xarray-sql#268 ·
维护者通常 3 天内回复
-
enhancement ml
难度 2/5 1-3 小时 新手友好度 64/100
xqlsystems/xarray-sql#267 · 4 条评论 ·
维护者通常 3 天内回复
-
难度 1/5 1 小时以内 新手友好度 74/100
xqlsystems/xarray-sql#243 ·
维护者通常 3 天内回复
查看 xqlsystems/xarray-sql 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
Textualize/textual#6753 · 1 条评论 ·
-
priority:low size:small
难度 2/5 1-3 小时 新手友好度 70/100
RonaldHensbergen/composable-data-stack#1177 ·
维护者通常 1 天内回复
-
Use registered media types for HDF5 and NetCDF, and stop claiming media_type must be IANA-registered未关闭documentation metadata
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 1 天内回复
-
check-typing: ty 0.0.98+ fails on the renamed rule `unresolved-import` (now `import-not-found`)可能已有人在做 @oberstet 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 91/100
crossbario/cfxdb#145 ·