Skip to content

Allow inline column aliases for create view #3108

@DaltonModlin

Description

@DaltonModlin

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

I'd like to enable SQL statements with the form:

CREATE VIEW view_name (c1_alias, c2_alias) AS
    SELECT
        column_name_1
        column_name_2
    FROM
        original_table

Describe the solution you'd like

In datafusion/sql/src/planner.rs on line 192, there is a check for empty columns before processing a create view statement. This empty column check stops inline create view statements like the one above as the columns are populated by the column aliases - in this case c1 and c2. I suggest removing the empty column check, and adding a few relevant tests (maybe within datafusion/core/src/datasource/view.rs?) to check everything is still in working order.

Describe alternatives you've considered
We could not do this and instead require that CREATE VIEW statements with column aliases are of the form:

CREATE VIEW view_name AS
    SELECT
        column_name_1 AS c1,
        column_name_2 AS c2,
    FROM
        original_table

Additional context
This change would assist in getting all TPCH queries to pass, in particular query #15.
See #166 for additional context on that issue, or see benchmarks/queries/q15.sql for the actual TPCH query 15 statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsqlSQL Planner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions