Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

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

维护者通常 1 天内回复

@med9110 已经在做这个了。

开始于 2026年10月14日。

评估

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

调研方向

从 (DataType::Struct(lhs), DataType::Struct(rhs)) 分支开始,该分支位于 datafusion/expr-common/src/type_coercion/binary.rs 的 type_union_resolution_coercion 中。让 search_corresponding_coerced_type 同时返回按名称匹配的 rhs 字段,并将该字段传给 coerce_fields,而不是按位置 zip。运行该文件中现有的 struct union coercion 测试,并添加一个字段顺序互换的用例。当 Struct { a: Int32 NOT NULL, b: Int32 NOT NULL } 与 Struct { b: Int32 NULL, a: Int32 NOT NULL } 做 union 得到 Struct { a: Int32 NOT NULL, b: Int32 NULL } 时即完成。

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

描述

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.

主要语言
Rust
星标
9.5k
派生
2.5k
平均合并
4 天 19 小时
30 天内合并 PR
342

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

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

apache/datafusion 的其他 Issue

查看 apache/datafusion 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

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