Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#26,333 コメント 0 件 リアクション 0 件 担当者 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時間
マージ済み PR(30日)
342

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/datafusion のほかの issue

apache/datafusion の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。