Skip to content

Wrong cast between structs with different field orderΒ #17285

@aroig

Description

@aroig

Describe the bug

We have observed that casting a struct with fields of the same type, to a schema that re-orders the fields, miss-assigns the values. It appears like the values are assigned positionally, instead of by field name.

To Reproduce

I've prepared a reproducing example here: https://github.com/aroig/datafusion-cast-bug

Just do cargo run to reproduce.

Expected behavior

I would expect that casting {"b": 3, "a": 4}, to schema {"a": Int, "b": Int} would produce {"a": 4, "b": 3}, however the obtained result is {"a": 3, "b": 4}, as if the values are assigned positionally instead of by field name.

Additional context

No response

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