Skip to content

Type casting error when reading files persisted with old schema for complex type #2617

Description

@jordepic

Apache Iceberg Rust version

None

Describe the bug

When a table's struct (or nested list/map) column has gained fields over time via schema evolution, reading data files written under the older schema fails with an Arrow cast error such as Cast error: Casting from Utf8 to Struct(...). The record-batch transformer reconciles a file's nested children to the table schema by position within the struct rather than by Iceberg field id, so once a nested struct adds a field, the children no longer line up and a mismatched cast is attempted (e.g. casting a string child into a struct slot). Files are valid and readable by Iceberg-Java/Spark.

e.g. struct goes from a, c to a, b, c -> when reading old file with only a, c it tries to cast c to type of b

To Reproduce

  1. Create a table with a column s struct<a: string> (plus other columns).
  2. Write a data file.
  3. Evolve the schema to s struct<a: string, b: long> (add a nested field), keeping field ids stable.
  4. Read the table (the older file still has s with only a).
  5. The scan errors with Cast error: Casting from Utf8 to Struct(...).

Expected behavior

Nested struct/list/map children are reconciled to the table schema by field id (recursively), and fields present in the table schema but absent from the file are materialized as typed NULLs — matching Iceberg's column-projection-by-id semantics. The read should succeed.

Willingness to contribute

I can contribute a fix for this bug independently

Activity

  1. changed the title [-]Reading a struct column that gained fields fails with "Cast error: Casting from Utf8 to Struct"[/-] [+]Type casting error when reading files persisted with old schema for complex type[/+] on Jun 10, 2026
  2. added 2 commits that reference this issue on Jun 14, 2026
    e33ca27
    5d42f1a
  3. added 2 commits that reference this issue on Jul 25, 2026
    5a87f33
    a780587
  4. ewoodbury commented on Sep 20, 2026

    @ewoodbury
    Contributor

    I hit this error as well (using Spark + Datafusion Comet) and could really use the fix - I'd be happy to do the legwork to revive the PR and try to get it merged in

  5. ewoodbury commented on Sep 20, 2026

    @ewoodbury
    Contributor

    Revived #2647 as #3255, rebased onto current main.

    This is @jordepic's original patch (authorship preserved) plus a small append-case unit test

  6. added a commit that references this issue on Oct 11, 2026
    050ddfd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions