Implement Spark-compatible `log1p`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
先阅读 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 内容生成。
描述
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
<= yAsymptotewithyAsymptote = -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.0is false).+InfinityreturnsInfinity. -0.0returns-0.0and0.0returns0.0(check the sign).- Tiny values (
1e-300,1e-20) return the input value, which is whereln(1 + x)would lose precision. - Bit-exact results: Spark uses fdlibm via
StrictMath. Rust'sf64::ln_1pcalls the platformlog1p, which can differ in the last ulp on some inputs and platforms. Compare againstStrictMath.log1pvalues for a range of inputs (e.g. 0.1 to 2.0 and large values like1e300), or use a port of fdlibms_log1p.cif 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 classesUnaryLogExpressionandUnaryMathExpression. - DataFusion core has no
log1p(it hasln,log,log2,log10). - Follow
crates/spark/src/function/math/expm1.rs(Signature::exact(vec![Float64]),exp_m1), usingln_1pand mappingx <= -1.0to NULL. - Tests: the placeholder
crates/sqllogictest/test_files/math/log1p.sltexists 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 分钟
- 30 天内合并 PR
- 26
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/datafusion-spark 的其他 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
apache/datafusion-spark#287 ·
维护者通常 1 天内回复
-
[Bug] make_dt_interval returns NULL for more than about 1.49 million days, Spark returns the interval可能已有人在做 @Subodh-17 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
apache/datafusion-spark#109 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 18/100
apache/datafusion-spark#299 ·
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 35/100
apache/datafusion-spark#298 ·
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 48/100
apache/datafusion-spark#297 ·
维护者通常 1 天内回复
查看 apache/datafusion-spark 的全部 Issue
相似的 Issue
-
comp-rbac
难度 2/5 1-3 小时 新手友好度 68/100
ClickHouse/ClickHouse#131875 ·
维护者通常 1 天内回复
-
bug(python): read_transaction raises TypeError on a Rewrite with rewritten indices可能已有人在做 @Borg93 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 75/100
lance-format/lance#11117 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
storytold/photocraft#15232 · 1 条评论 ·
维护者通常 1 天内回复
-
forge: fork preflight reads still send `requireCanonical: false`, which Rootstock rejects (-32603)可能已有人在做 @Ynyesto 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
foundry-rs/foundry#18485 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
bondybondbond/rushcut#238 · 1 条评论 ·