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

Create Struct table with explicit type and name #10207

Closed
jayzhan211 opened this issue Apr 24, 2024 · 2 comments · Fixed by #10273
Closed

Create Struct table with explicit type and name #10207

jayzhan211 opened this issue Apr 24, 2024 · 2 comments · Fixed by #10273
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?

Currently we can build struct table like this

statement ok
create table t as values (struct(1, 'a')), (struct(2, 'b'));

query ?
select * from t;
----
{c0: 1, c1: a}
{c0: 2, c1: b}

If we want to name them, we need to build with named_struct

statement ok
create table t as values (named_struct('number', 1, 'varchar', 'a')), (named_struct('number', 2, 'varchar', 'b'));

query ?
select * from t;
----
{number: 1, varchar: a}
{number: 2, varchar: b}

I hope we can build the struct table with pre-defined type and name

statement error DataFusion error: This feature is not implemented: Unsupported SQL type Custom\(ObjectName\(\[Ident \{ value: "struct", quote_style: None \}\]\), \["n", "int", "s", "varchar"\]\)
create table t (s struct(n int, s varchar)) as values (struct(1, 'a')), (struct(2, 'b'));

query ?
select * from t;
----
{n: 1, s: a}
{n: 2, s: b}

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

Similar to DuckDB
https://duckdb.org/docs/sql/data_types/struct#creating-structs-with-the-row-function

@duongcongtoai
Copy link
Contributor

i would like to work on this

@duongcongtoai
Copy link
Contributor

duongcongtoai commented Apr 28, 2024

1st item:

create table t (s struct(n int, s varchar))

I think upstream sqlparser lib already support similar syntax

create table t (s struct<n int, s varchar>);

But only bigquery dialect support this syntax.
However in this PR where struct syntax is is added they also decided to support this syntax for both Bigquery and GenericDialect, and i think they forgot to add | GenericDialect for the column definition parsing logic here

Ticket to follow: apache/datafusion-sqlparser-rs#1240

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

Successfully merging a pull request may close this issue.

2 participants