Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug] atan2 does not normalize -0.0 the way Spark does

未关闭 适合新手
#26,333 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@spicysharkco 已经在做这个了。

开始于 2026年10月15日。

  • #26394 来自 @spicysharkco —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust, sql
领域
databases

调研方向

修复位于 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 内容生成。

描述

bug spark
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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/datafusion 的其他 Issue

查看 apache/datafusion 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。