[Bug] format_string panics when the format argument is a NULL-typed column

未关闭 适合新手
#431 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
backend, databases

调研方向

从 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/datafusion-spark 的其他 Issue

查看 apache/datafusion-spark 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。