Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Union as a function #10206

Open
jayzhan211 opened this issue Apr 24, 2024 · 5 comments
Open

Support Union as a function #10206

jayzhan211 opened this issue Apr 24, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@jayzhan211
Copy link
Contributor

jayzhan211 commented Apr 24, 2024

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
@jayzhan211 jayzhan211 added the enhancement New feature or request label Apr 24, 2024
@jayzhan211 jayzhan211 changed the title Support Union Support Union Type Apr 24, 2024
@jayzhan211 jayzhan211 changed the title Support Union Type Support Union as a function Apr 24, 2024
@vaibhawvipul
Copy link

I would like to work on this.

@samuelcolvin
Copy link
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

@vaibhawvipul
Copy link

vaibhawvipul commented Apr 25, 2024

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.

@vaibhawvipul
Copy link

take

@gstvg
Copy link
Contributor

gstvg commented Jun 25, 2024

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 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants