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

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

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

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

評価

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

調査の方向性

crates/spark/src/function/string/format_string.rsから始め、特に issue が NULL の処理漏れを指摘している、202〜209 行付近の配列パスを確認してください。既存のスカラーでの NULL の動作と、crates/sqllogictest/test_files/string/format_string_null_format.sltにある sqllogictest の例を確認してください。issue にはそのテストを実行するコマンドが示されています。NULL 型のフォーマット列が panic を起こさず各行で NULL を返し、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時間
マージ済み PR(30日)
96

環境構築

はじめの一歩

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

apache/datafusion-spark のほかの issue

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

似ている issue

Rust の issue をもっと見る

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

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