Skip to content

Support Union as a function #10206

Closed
Closed

Description

@jayzhan211

Is your feature request related to a problem or challenge?

We have recently issues show that it is time to support Union

#10161 #10139 ScalarValue::iter_to_array
#10180 comparison_coercion

I think the first step is able to create Union in slt file.

Describe the solution you'd like

Follow DuckDB Union or others well-known system.

https://duckdb.org/docs/sql/data_types/union.html

First step might be able to create table with union type

query error DataFusion error: Error during planning: Inconsistent data type across values list at row 1 column 0\. Was Int64 but found Utf8
create table t1 (u union(num interger, str varchar)) as values
  (1),
  ('two');

Describe alternatives you've considered

No response

Additional context

  1. Built Union on top of Struct
  2. Impl with ScalarUDFImpl

Activity

  1. changed the title [-]Support `Union`[/-] [+]Support `Union` Type[/+] on Apr 24, 2024
  2. changed the title [-]Support `Union` Type[/-] [+]Support `Union` as a function[/+] on Apr 24, 2024
  3. vaibhawvipul commented on Apr 24, 2024

    @vaibhawvipul

    I would like to work on this.

  4. samuelcolvin commented on Apr 24, 2024

    @samuelcolvin
    Contributor

    As I mentioned here #7845 (comment), the most useful thing for me would be less ugly errors when you do try to compare a union with something else.

    Also it would be good to be able to force people to cast unions in my case, so it would be nice if we could switch off comparison_coercion somehow.

    @vaibhawvipul if you're working on this, you might be interested in my logic in datafusion-contrib/datafusion-functions-json/src/common_union.rs

  5. vaibhawvipul commented on Apr 25, 2024

    @vaibhawvipul

    As I mentioned here #7845 (comment), the most useful thing for me would be less ugly errors when you do try to compare a union with something else.

    Also it would be good to be able to force people to cast unions in my case, so it would be nice if we could switch off comparison_coercion somehow.

    @vaibhawvipul if you're working on this, you might be interested in my logic in datafusion-contrib/datafusion-functions-json/src/common_union.rs

    This was helpful @samuelcolvin. Thank you.

    My approach is similar -

    • adding support for arrow union datatype
    • update planner
    • need to support cast
    • will be extending functions to have union functions like union_extract.
  6. vaibhawvipul commented on May 16, 2024

    @vaibhawvipul

    take

  7. gstvg commented on Jun 25, 2024

    @gstvg
    Contributor

    I opened a PR that adds support for Union datatype on sqlparser which I hope can help here. If so, some review would be very appreciated, since sqlparser-rs dev-bandwith is a bit limited. Thanks 🙏

  8. alamb commented on Jan 13, 2026

    @alamb
    Contributor
  9. alamb commented on Jan 13, 2026

    @alamb
    Contributor

    Let's open follow on tickets with any specific features we want to support

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions