read_side_padding ignores the pad string for dictionary inputs in lpad and rpad

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

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

问题位于 native/spark-expr/src/static_invoke/char_varchar_utils/read_side_padding.rs 中处理 Dictionary 输入的三参数分支:两个 Dictionary 分支都传入了 SPACE,而 Utf8 和 LargeUtf8 分支传入的是填充字符串。请先阅读该分支,然后添加一个单元测试,使用 Dictionary 输入和非空格的填充字符串(例如 "x"),期望结果为 ["abxxx", "abxxx"]。当同一输入下 Dictionary 的结果与 Utf8 的结果一致时,即完成。

由索引模型根据 Issue 内容生成。

描述

requires-triage
Describe the bug

In read_side_padding.rs, the three-argument arm ([Array, Scalar(Int32), Scalar(Utf8)]) ignores the pad string when the input is a dictionary array. The Utf8 and LargeUtf8 branches pass string to spark_read_side_padding_internal, but both Dictionary branches pass SPACE. So rpad/lpad with a custom pad pads with spaces instead.

https://github.com/apache/datafusion-comet/blob/644a8708839270d382a78715fca7e2b724143588/native/spark-expr/src/static_invoke/char_varchar_utils/read_side_padding.rs#L115-L132

Steps to reproduce

Kernel-level, on main at 644a87088:

let dict: DictionaryArray<Int32Type> = vec!["ab", "ab"].into_iter().collect();
let args = vec![
    ColumnarValue::Array(Arc::new(dict)),
    ColumnarValue::Scalar(ScalarValue::Int32(Some(5))),
    ColumnarValue::Scalar(ScalarValue::Utf8(Some("x".to_string()))),
];
spark_rpad(&args) // ["ab   ", "ab   "]

I couldn't find a SQL query that reaches this today. The native scan input unpacks dictionary-encoded strings (see test_unpack_dictionary_string in planner.rs), and the existing string_rpad.sql tests with a custom pad pass. So this looks latent, but it would give silent wrong results if a dictionary array ever reaches the kernel, which is what the Dictionary arm (added for SPARK-48498) is there for.

Expected behavior

["abxxx", "abxxx"], the same as for a Utf8 input.

Additional context

Found while reviewing my change for #7245 (PR #7450). The fix is to pass string instead of SPACE in the two Dictionary branches and add a unit test with a dictionary input and a non-space pad.

Willingness to contribute

I can contribute a fix for this bug independently

AI disclosure: this issue was investigated and written with an AI coding assistant, and reviewed by me.

主要语言
Scala
星标
1.3k
派生
405
平均合并
3 天 3 小时
30 天内合并 PR
269

环境准备

从这里开始

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

apache/datafusion-comet 的其他 Issue

查看 apache/datafusion-comet 的全部 Issue

相似的 Issue

更多 Scala Issue

把新 issue 发到你的邮箱

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