[Bug] atan2 does not normalize -0.0 the way Spark does
维护者通常 1 天内回复
评估
调研方向
修复位于 datafusion/spark/src/function/math/atan2.rs 中的 SparkAtan2,其中原始参数被直接传给 f64::atan2;按 issue 所述,先给两个操作数都加上 0.0。需要修改的期望值位于 datafusion/sqllogictest/test_files/spark/math/atan2.slt 第 155 行,从 -3.14159 改为 3.141592653589793。运行该 sqllogictest 文件,并在完成前确认 atan2(0.0, -0.0) 和 atan2(-0.0, -0.0) 与 issue 中报告的 Spark 结果一致。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
SparkAtan2 passes the raw arguments to Rust's f64::atan2 (atan2.rs#L82). Spark's Atan2 adds 0.0 to both arguments first, which turns a negative zero into a positive zero (mathExpressions.scala#L1229-L1237). The Spark source explains why: "With codegen, the values returned by -0.0 and 0.0 are different. Handled with +0.0".
So atan2 returns a different value whenever y or x is -0.0.
To Reproduce
Spark 4.0.0:
SELECT atan2(CAST('-0.0' AS DOUBLE), -1.0D)
-- 3.141592653589793
SELECT atan2(0.0D, CAST('-0.0' AS DOUBLE))
-- 0.0
SELECT atan2(CAST('-0.0' AS DOUBLE), CAST('-0.0' AS DOUBLE))
-- 0.0
DataFusion: the existing test at atan2.slt#L155 documents the C99 result:
query R
SELECT atan2(-0.0::double, -1.0::double)
----
-3.141592653589793
The other two inputs were not run on DataFusion. By the C99 definition that Rust follows, atan2(0.0, -0.0) is pi and atan2(-0.0, -0.0) is -pi.
Expected behavior
Add 0.0 to both arguments before calling atan2, as Spark does, and change the expectation at atan2.slt#L155 to 3.141592653589793.
Additional context
Found by running the queries in datafusion/sqllogictest/test_files/spark on a local Spark and comparing the results with the expected values in the files, which is the kind of check proposed in #17045. Spark results come from Apple's build of Spark 4.0.0 (4.0.0.65-apple) with a UTC session and spark.sql.ansi.enabled=false unless stated. The Spark source links point at the v4.0.0 tag. DataFusion results are the sqllogictest expectations at 9dec77584, which CI enforces. Anything marked as not run was derived from reading the code.
- 主要语言
- Rust
- 星标
- 9.5k
- 派生
- 2.5k
- 平均合并
- 4 天 19 小时
- 30 天内合并 PR
- 342
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/datafusion 的其他 Issue
-
bug help wanted unparser
难度 2/5 1-3 小时 新手友好度 72/100
apache/datafusion#26316 · 1 条评论 ·
维护者通常 1 天内回复
-
Deduplicate bucket computation in width_bucket_interval_mdn_exact可能已有人在做 @nightcityblade 于 2 天前认领。 未关闭enhancement good first issue help wanted spark tech debt
难度 2/5 1-3 小时 新手友好度 85/100
apache/datafusion#26307 · 3 条评论 ·
维护者通常 1 天内回复
-
Use the shared aggr_test_schema in CSV scan tests instead of a local copy可能已有人在做 @med9110 于 2 天前认领。 未关闭core enhancement good first issue help wanted tech debt
难度 2/5 1-3 小时 新手友好度 85/100
apache/datafusion#26306 · 2 条评论 ·
维护者通常 1 天内回复
-
gcd benchmarks pass number_rows: 0 for 100k-row inputs可能已有人在做 @med9110 于 2 天前认领。 未关闭bug functions good first issue help wanted tech debt
难度 1/5 1 小时以内 新手友好度 92/100
apache/datafusion#26297 · 1 条评论 ·
维护者通常 1 天内回复
-
Struct union type coercion takes field nullability from the wrong field when field order differs可能已有人在做 @med9110 于 2 天前认领。 未关闭bug help wanted logical-expr tech debt
难度 2/5 1-3 小时 新手友好度 68/100
apache/datafusion#26296 · 1 条评论 ·
维护者通常 1 天内回复
查看 apache/datafusion 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
EmbarkStudios/cargo-deny#910 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
tursodatabase/turso#10054 ·
维护者通常 1 天内回复
-
build: Update rust version可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭dependencies
难度 2/5 1-3 小时 新手友好度 67/100
ibm-granite-community/granite-cli#229 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
orottier/web-audio-api-rs#658 ·