Skip to content

Create Struct table with explicit type and name #10207

Closed

Description

@jayzhan211

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

Activity

  1. duongcongtoai commented on Apr 27, 2024

    @duongcongtoai
    Contributor

    i would like to work on this

  2. duongcongtoai commented on Apr 28, 2024

    @duongcongtoai
    Contributor

    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

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