lpad/rpad do not use withNullShortCircuit, so ANSI errors are raised on rows Spark skips

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

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

lpad/rpad 的序列化器是 spark/src/main/scala/org/apache/comet/serde/strings.scala 中的 CometStringLPad 和 CometStringRPad(大约第 568-620 行)。阅读 QueryPlanSerde.scala 中的 withNullShortCircuit,以及 arrays.scala 如何使用它,然后以相同方式包装这两个 proto。完成标准是:复现代码的 NULL 输入配合 ANSI 类型转换时,lpad 和 rpad 都返回 NULL,并附带一个覆盖该情况的 SQL 文件测试。

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

描述

requires-triage
Describe the bug

CometStringLPad and CometStringRPad build their native expression with scalarFunctionExprToProto and do not wrap it in withNullShortCircuit:

In Spark, StringLPad / StringRPad are TernaryExpressions with nullIntolerant = true. TernaryExpression.eval evaluates the len and pad children only when str is non-null. Comet evaluates all children for every row, so when a child can fail (for example an ANSI cast), Comet can raise an error on a row where str is NULL and Spark would have returned NULL without evaluating that child.

This came up in review of https://github.com/apache/datafusion-comet/pull/7450: https://github.com/apache/datafusion-comet/pull/7450#discussion_r4511335598

Steps to reproduce

Found by reading the code; I have not run this repro yet.

SET spark.sql.ansi.enabled=true;
CREATE TABLE tbl(s STRING, t STRING) USING parquet;
INSERT INTO tbl VALUES (NULL, 'abc');
SELECT lpad(s, CAST(t AS INT)) FROM tbl;
SELECT rpad(s, CAST(t AS INT)) FROM tbl;
Expected behavior

Both queries return NULL, as Spark does, because s is NULL and Spark never evaluates CAST(t AS INT) for that row. Comet is expected to raise a cast error instead.

Additional context

Other serdes already use withNullShortCircuit for this (for example in arrays.scala, maps.scala and datetime.scala). The fix is probably to wrap the lpad/rpad proto in withNullShortCircuit and add a SQL file test for the case above.

Willingness to contribute

I can contribute a fix for this bug independently

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

环境准备

从这里开始

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

apache/datafusion-comet 的其他 Issue

查看 apache/datafusion-comet 的全部 Issue

相似的 Issue

更多 Scala Issue

把新 issue 发到你的邮箱

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