Implement Spark-compatible `positive`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
The template is crates/spark/src/function/math/negative.rs: copy its signature, NumericAndInterval types and implicit-cast handling, and register the function with the other math functions. Read Spark's UnaryPositive and datafusion/sql/src/expr/unary_op.rs for the timestamp/Duration divergence, then add ScalarUDFImpl::simplify replacing the call with its child. Enable the commented query in crates/sqllogictest/test_files/math/positive.slt and extend it with the NULL, integer-boundary, float, decimal, string-cast, interval and rejected-type cases; done is that file passing.
由索引模型根据 Issue 内容生成。
描述
Part of #174 and apache/datafusion-comet#7300.
What the function does
positive(expr) (also the unary +expr operator) returns expr unchanged. It accepts numeric and interval types (TypeCollection.NumericAndInterval, with ImplicitCastInputTypes, so a STRING argument is cast to DOUBLE). The result type equals the (cast) input type; NULL in gives NULL out. Available since 1.5.0.
In Spark 4.0+ UnaryPositive is RuntimeReplaceable with replacement = child, so it disappears from optimized plans. In 3.4 and 3.5 it is a regular expression that survives into physical plans.
Examples
SELECT positive(1);
-- 1
SELECT positive('-1.11'), positive(-1.11);
-- -1.11 -1.11 (double, decimal(3,2))
SELECT +interval '-1 year 1 month';
-- -0-11 interval year to month
SELECT +interval '-1 day 1 hour -1 minute 1 second';
-- -0 23:00:59.000000000
SELECT +date '1999-01-01';
-- error DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE
Edge cases to test
- NULL input of each type.
- Every integer type keeps its type and value, including
-2147483648and-9223372036854775808(no overflow, unlikenegative). - FLOAT / DOUBLE: NaN, -0.0 (sign preserved), +/-Infinity returned unchanged.
- DECIMAL keeps precision and scale (
positive(-1.11)isDECIMAL(3,2)). - STRING argument is cast to DOUBLE (
positive('-1.11')is DOUBLE-1.11). With ANSI on an invalid string fails in the cast (CAST_INVALID_INPUT); with ANSI off it is NULL. - Year-month and day-time intervals are returned unchanged (
Interval(YearMonth)andDuration(Microsecond)in this crate). - DATE, TIMESTAMP, BOOLEAN, BINARY are rejected with
DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE(requiredType("NUMERIC" or "INTERVAL DAY TO SECOND" or "INTERVAL YEAR TO MONTH" or "INTERVAL")). - Scalar and array inputs.
Differences across Spark versions
- 3.4 / 3.5:
UnaryPositiveis evaluated as an expression (identitynullSafeEval). - 4.0+:
RuntimeReplaceable, replaced by its child during optimization. Behaviour is the same.
Implementation notes
- Spark:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala,UnaryPositive. - DataFusion core has no
positivefunction. Its SQL planner accepts+exprfor numeric, interval and timestamp operands and returns the operand unchanged (datafusion/sql/src/expr/unary_op.rs); Spark rejects timestamps, and Spark day-time intervals arrive here asDuration, which that check may not cover. - Mirror
crates/spark/src/function/math/negative.rs(same signature and types) and return the input as-is. ImplementingScalarUDFImpl::simplifyto replace the call with its argument is also appropriate. - Tests: the placeholder
crates/sqllogictest/test_files/math/positive.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 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 80/100
apache/datafusion-spark#266 ·
维护者通常 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 天内回复
查看 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 条评论 ·