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

Đang mở Phù hợp với người mới
#7,583 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
scala, spark
Lĩnh vực
data-engineering

Hướng nghiên cứu

Các serde lpad/rpad là CometStringLPad và CometStringRPad trong spark/src/main/scala/org/apache/comet/serde/strings.scala (khoảng dòng 568-620). Hãy đọc withNullShortCircuit trong QueryPlanSerde.scala và cách arrays.scala sử dụng nó, sau đó bọc cả hai proto theo cách tương tự. Hoàn thành khi đầu vào NULL của reproducer với phép ép kiểu ANSI trả về NULL cho lpad và rpad, kèm một bài kiểm thử tệp SQL bao phủ trường hợp đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Scala
Star
1.3k
Fork
414
Merge trung bình
3 ngày 5 giờ
Pull request đã merge (30 ngày)
210

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/datafusion-comet

Tất cả issue của apache/datafusion-comet

Issue tương tự

Thêm issue về Scala

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.