Implement Spark-compatible `log1p`

オープン 初心者向け
#266 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
80/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
database

調査の方向性

まず crates/spark/src/function/math/expm1.rs を読み、Signature::exact(vec![Float64]) パターン、#[user_doc] アノテーション、null の扱いを確認してから、新しい関数を同じ方法で登録してください。ln_1p を実装し、<= -1.0 の入力はすべて NULL にマッピングして、Spark の UnaryLogExpression と一致させます。crates/sqllogictest/test_files/math/log1p.slt のプレースホルダークエリを有効化して拡張し、その slt ファイルを実行します。完了とは、NULL、-1.0、-Infinity、NaN、Infinity、-0.0、および極小値の slt ケースが通り、結果が StrictMath.log1p と一致することです。

索引モデルが issue の本文から書いたものです。

説明

enhancement good first issue

Part of #174 and apache/datafusion-comet#7300.

What the function does

log1p(expr) returns ln(1 + expr), computed accurately for expr near 0. The argument is implicitly cast to DOUBLE (UnaryMathExpression, inputTypes = Seq(DoubleType)) and the result is DOUBLE. Like the other Hive-derived log functions (UnaryLogExpression), any input <= -1.0 returns NULL instead of -Infinity or NaN. The result is always nullable. Available since 1.4.0.

Spark evaluates java.lang.StrictMath.log1p (fdlibm) in both the interpreted and code-generated paths.

Examples
SELECT log1p(0);
-- 0.0
SELECT log1p(-1);
-- NULL
SELECT log1p(-2);
-- NULL
SELECT log1p(CAST('NaN' AS DOUBLE));
-- NaN
SELECT log1p(CAST('Infinity' AS DOUBLE));
-- Infinity

MathExpressionsSuite checks log1p against StrictMath.log1p for 0.0, 0.1, ..., 2.0 and expects NULL for -10.0, -9.0, ..., -1.0.

Edge cases to test
  • NULL input.
  • Exactly -1.0 returns NULL (the boundary is <= yAsymptote with yAsymptote = -1.0), and values just above it (e.g. -0.9999999999999999) return a large negative finite value.
  • Values below -1 (including -Infinity) return NULL, not NaN.
  • NaN returns NaN (NaN <= -1.0 is false). +Infinity returns Infinity.
  • -0.0 returns -0.0 and 0.0 returns 0.0 (check the sign).
  • Tiny values (1e-300, 1e-20) return the input value, which is where ln(1 + x) would lose precision.
  • Bit-exact results: Spark uses fdlibm via StrictMath. Rust's f64::ln_1p calls the platform log1p, which can differ in the last ulp on some inputs and platforms. Compare against StrictMath.log1p values for a range of inputs (e.g. 0.1 to 2.0 and large values like 1e300), or use a port of fdlibm s_log1p.c if they differ.
  • Integer, DECIMAL, FLOAT and STRING arguments (cast to DOUBLE first; with ANSI on an invalid string fails in the cast).
Differences across Spark versions

None found (3.4 through 4.2; only contextIndependentFoldable was added).

Implementation notes
  • Spark: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala, Log1p, base classes UnaryLogExpression and UnaryMathExpression.
  • DataFusion core has no log1p (it has ln, log, log2, log10).
  • Follow crates/spark/src/function/math/expm1.rs (Signature::exact(vec![Float64]), exp_m1), using ln_1p and mapping x <= -1.0 to NULL.
  • Tests: the placeholder crates/sqllogictest/test_files/math/log1p.slt exists with a commented-out query; enable and extend it. Document with #[user_doc].

This issue was generated by an LLM (Claude) from the Apache Spark source code and tests. Examples come from Spark's ExpressionDescription examples, test suites and .sql.out golden files, but please verify them against Spark before relying on them.

主要言語
Rust
スター
7
フォーク
15
平均マージ
16時間 43分
マージ済み PR(30日)
26

環境構築

はじめの一歩

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

apache/datafusion-spark のほかの issue

apache/datafusion-spark の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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