lpad/rpad do not use withNullShortCircuit, so ANSI errors are raised on rows Spark skips
维护者通常 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 内容生成。
描述
Describe the bug
CometStringLPad and CometStringRPad build their native expression with scalarFunctionExprToProto and do not wrap it in withNullShortCircuit:
- https://github.com/apache/datafusion-comet/blob/8f4ce5e643e9c10803369dae6a1646195f36cb72/spark/src/main/scala/org/apache/comet/serde/strings.scala#L568-L620
withNullShortCircuit: https://github.com/apache/datafusion-comet/blob/8f4ce5e643e9c10803369dae6a1646195f36cb72/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala#L1408
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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/datafusion-comet 的其他 Issue
-
bug priority:medium
难度 2/5 1-3 小时 新手友好度 73/100
apache/datafusion-comet#7559 · 1 条评论 ·
维护者通常 2 天内回复
-
area:writer bug priority:low
难度 2/5 1-3 小时 新手友好度 78/100
apache/datafusion-comet#7558 ·
维护者通常 2 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
apache/datafusion-comet#7557 ·
维护者通常 2 天内回复
-
`rand` and `randn` with an integer seed fall back to Spark without a fallback reason可能已有人在做 @galaxytemple 于 3 天前认领。 未关闭requires-triage
难度 2/5 1-3 小时 新手友好度 78/100
apache/datafusion-comet#7479 · 1 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
area:writer enhancement requires-triage
难度 2/5 1-3 小时 新手友好度 62/100
apache/datafusion-comet#7463 ·
维护者通常 2 天内回复
查看 apache/datafusion-comet 的全部 Issue
相似的 Issue
-
A-api C-bug S-ready-for-human
难度 2/5 1-3 小时 新手友好度 70/100
ergoplatform/ergo#2932 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
lichess-org/lila#22454 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
chipsalliance/rocket-chip#3845 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 1/5 1 小时以内 新手友好度 86/100
维护者通常 13 天内回复