Skip to content

Support cast between StructArray. #5219

Closed
@my-vegetable-has-exploded

Description

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

In apache/datafusion#6635, we think supporting cast between StructArray will be helpful to implement multi column In list.

For example,

❯ CREATE TABLE colors (
    color_id INT PRIMARY KEY,
    color_name VARCHAR(50)
);
0 rows in set. Query took 0.002 seconds.

❯ INSERT INTO colors (color_id, color_name) VALUES (1, 'Red'), (2, 'Blue');
+-------+
| count |
+-------+
| 2     |
+-------+
1 row in set. Query took 0.002 seconds.

❯ SELECT * FROM colors WHERE struct(color_id) IN (struct(1));
type_coercion
caused by
Error during planning: Can not find compatible types to compare Struct([Field { name: "c0", data_type: Int32, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]) with [Struct([Field { name: "c0", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }])]

After supporting cast between StructArray, we can just use struct(color_id) IN (struct(1)) rather than struct(color_id) IN (struct(arrow_cast(1,'Int32'))); in this example.

Describe the solution you'd like

  • check can_cast_types recursively for each field
  • cast_with_options recursively for each field

Describe alternatives you've considered

Additional context

I'm willing to submit a pr later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrowChanges to the arrow crateenhancementAny new improvement worthy of a entry in the changelog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions