[Bug] format_string panics when the format argument is a NULL-typed column
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 crates/spark/src/function/string/format_string.rs 开始,尤其检查第 202–209 行附近的数组路径,issue 指出这里缺少对 NULL 的处理。检查现有的标量 NULL 行为,以及 crates/sqllogictest/test_files/string/format_string_null_format.slt 中的 sqllogictest 示例;issue 给出了运行该测试的命令。完成标准是:NULL 类型的格式列对每一行都返回 NULL,且不会 panic;通过 printf 别名调用时也如此。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
format_string panics with internal error: entered unreachable code when the format argument is a column of type NULL, for example a VALUES column that only holds NULL. Spark casts such a column to STRING and returns NULL for every row.
return_field_from_args accepts DataType::Null (format_string.rs#L108) and the scalar path returns NULL for ScalarValue::Null (#L134). The array path has no case for it: try_as_str() returns None and reaches unreachable!() (#L202). The match on the result type after the loop has no NULL arm either (#L209).
To Reproduce
SELECT format_string(f, a) FROM (VALUES (NULL, CAST(1 AS INT)), (NULL, CAST(2 AS INT))) AS t(f, a);
datafusion-spark panics:
panicked at crates\spark\src\function\string\format_string.rs:202:30:
internal error: entered unreachable code
A NULL literal format (format_string(NULL, CAST(1 AS INT))) and a NULL STRING column both return NULL, so only a NULL-typed column fails. The printf alias panics the same way.
sqllogictest file with Spark's results (fails today)
Save it as crates/sqllogictest/test_files/string/format_string_null_format.slt and run cargo test -p datafusion-spark-sqllogictest -- format_string_null_format. Today both modes fail with the panic.
query T
SELECT format_string(f, a) FROM (VALUES (NULL, CAST(1 AS INT)), (NULL, CAST(2 AS INT))) AS t(f, a);
----
NULL
NULL
Expected behavior
As in Spark:
NULL
NULL
Spark versions
Spark 4.2.0, from the source; not run on a live Spark. FormatString is ImplicitCastInputTypes and declares STRING for the format (stringExpressions.scala#L2066-L2068). A NULL-typed argument is cast to the expected type (TypeCoercion.scala#L202; with ANSI mode on, Cast.scala#L389), and a NULL format gives NULL (stringExpressions.scala#L2080-L2083). Spark accepts a NULL-only VALUES column, as in its own test sql-tests/inputs/group-by.sql. 3.5.8, 4.0.4 and 4.1.3 have the same logic.
datafusion-spark version
main at ab9d308
Additional context
Reproduced on main ab9d308 with the sqllogictest runner in simplify and evaluate mode, and with datafusion-spark-cli with ANSI mode on and off. unreachable!() panics in release builds too.
cc @andygrove
- 主要语言
- Rust
- 星标
- 13
- 派生
- 31
- 平均合并
- 2 天 2 小时
- 30 天内合并 PR
- 96
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/datafusion-spark 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 84/100
apache/datafusion-spark#440 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
apache/datafusion-spark#439 ·
维护者通常 1 天内回复
-
[Bug] width_bucket returns NULL for an infinite value可能已有人在做 @vaidik787 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
apache/datafusion-spark#424 ·
维护者通常 1 天内回复
-
[Bug] format_string with %#e puts the decimal point after the exponent可能已有人在做 @vaidik787 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 80/100
apache/datafusion-spark#423 ·
维护者通常 1 天内回复
-
[Bug] parse_url ignores the key for a part other than QUERY, Spark returns NULL可能已有人在做 @Aryan2210 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 64/100
apache/datafusion-spark#409 · 2 条评论 ·
维护者通常 1 天内回复
查看 apache/datafusion-spark 的全部 Issue
相似的 Issue
-
autofix:working
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 75/100
libracoder/kiri#1138 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
roc-lang/basic-webserver#277 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 82/100
samkerrcode/opengent#113 ·
维护者通常 1 天内回复
-
app bug session
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复