Skip to content

Make CREATE EXTERNAL TABLE more user friendly #6248

Closed
@alamb

Description

@alamb

Is your feature request related to a problem or challenge?

At the moment, the CREATE EXTERNAL TABLE command requires all clauses in an exact order: https://arrow.apache.org/datafusion/user-guide/sql/ddl.html#create-external-table

So this is great:

CREATE EXTERNAL TABLE test
STORED AS CSV
WITH HEADER ROW
LOCATION '/path/to/directory/of/files';

However, generates a somewhat confusing syntax error:

CREATE EXTERNAL TABLE test
WITH HEADER ROW
STORED AS CSV
LOCATION '/path/to/directory/of/files';
 🤔 Invalid statement: sql parser error: Expected STORED, found: WITH

I think #6247 will help but we can do better

Describe the solution you'd like

I would like to extend the CREATE EXTERNAL TABLE syntax parser so the various clauses can be provided in any order and people don't have to put them in a specific order

Aka I want this (and similar) to work:

CREATE EXTERNAL TABLE test
WITH HEADER ROW
STORED AS CSV
LOCATION '/path/to/directory/of/files';

parser code is here: https://github.com/apache/arrow-datafusion/blob/main/datafusion/sql/src/parser.rs

There is an example of doing similar things in sqlparser-rs for CREATE FUNCTION: https://github.com/sqlparser-rs/sqlparser-rs/blob/b29b551fa111bbd50c40568f6aea6c49eafc0b9c/src/parser.rs#L2673-L2702

Describe alternatives you've considered

No response

Additional context

I am trying to help here: #6247

I struggled with this syntax while trying to port some sqllogictests: #6234

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions