Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Struct union type coercion takes field nullability from the wrong field when field order differs

Đang mở Phù hợp với người mới
#26,296 1 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 1 ngày

@med9110 đang làm issue này rồi.

Từ ngày 14/10/2026.

Đá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
68/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ệ
rust
Lĩnh vực
databases

Hướng nghiên cứu

Bắt đầu từ nhánh (DataType::Struct(lhs), DataType::Struct(rhs)) nằm trong type_union_resolution_coercion ở datafusion/expr-common/src/type_coercion/binary.rs. Cho search_corresponding_coerced_type trả về thêm trường rhs có cùng tên, và truyền trường đó vào coerce_fields thay vì zip theo vị trí. Chạy các test coercion union struct hiện có trong file đó và thêm một trường hợp với thứ tự trường bị đảo. Hoàn thành khi Struct { a: Int32 NOT NULL, b: Int32 NOT NULL } union với Struct { b: Int32 NULL, a: Int32 NOT NULL } cho ra Struct { a: Int32 NOT NULL, b: Int32 NULL }.

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

Mô tả

bug help wanted logical-expr tech debt
Describe the bug

In the (DataType::Struct(lhs), DataType::Struct(rhs)) arm of type_union_resolution_coercion (type_coercion/binary.rs#L835-L872), each field's coerced type is computed by matching fields by name (search_corresponding_coerced_type), but the field's nullability is computed by zipping lhs and rhs positionally:

let coerced_types = lhs
    .iter()
    .map(|lhs_field| search_corresponding_coerced_type(lhs_field, rhs))
    .collect::<Option<Vec<_>>>()?;

// preserve the field name and nullability
let orig_fields = std::iter::zip(lhs.iter(), rhs.iter());

let fields: Vec<FieldRef> = coerced_types
    .into_iter()
    .zip(orig_fields)
    .map(|(datatype, (lhs, rhs))| coerce_fields(datatype, lhs, rhs))
    .collect();

coerce_fields sets nullable = lhs.is_nullable() || rhs.is_nullable(). When the two structs have the same field names in a different order, the nullability of each output field comes from an unrelated right-hand field.

To Reproduce

Resolve the union type of:

  • lhs = Struct { a: Int32 NOT NULL, b: Int32 NOT NULL }
  • rhs = Struct { b: Int32 NULL, a: Int32 NOT NULL }

The result is Struct { a: Int32 NULL, b: Int32 NOT NULL }. Field b is reported as non-nullable even though the right-hand b can contain nulls (and a is needlessly marked nullable).

Expected behavior

Nullability is taken from the name-matched pair, giving Struct { a: Int32 NOT NULL, b: Int32 NULL }. For example, have search_corresponding_coerced_type return the matched rhs_field along with the coerced type, and pass that field to coerce_fields.

Additional context

The nearby try_type_union_resolution_with_struct (about L900-L970) walks data_types three times, each re-matching DataType::Struct with an internal_err! fallback the first loop already rules out. It may be worth simplifying in the same change.

Line references are pinned to commit 0d79252f61bd.

Ngôn ngữ chính
Rust
Star
9.4k
Fork
2.5k
Merge trung bình
4 ngày 9 giờ
Pull request đã merge (30 ngày)
329

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

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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

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

Issue tương tự

Thêm issue về Rust

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.