Skip to content

DESCRIBE should accept optional TABLE keyword #51

@fupelaqu

Description

@fupelaqu

Description

The SQL parser requires DESC TABLE <name> or DESCRIBE TABLE <name> with the TABLE keyword mandatory. However, tools like Apache Superset send DESC <name> without the TABLE keyword, which is the standard MySQL/PostgreSQL syntax.

Similarly, DESC <view_name> should work for materialized views when no qualifier is provided.

Example

-- Currently accepted
DESC TABLE ecommerce
DESCRIBE TABLE ecommerce

-- Should also be accepted (TABLE keyword optional)
DESC ecommerce
DESCRIBE ecommerce

Expected Behaviour

The TABLE keyword should be optional in DESCRIBE/DESC statements. When omitted, the parser should default to describing a table (or resolve to a materialized view if no table matches).

Impact

  • Superset compatibility: Superset sends DESC <name> via SQL Lab, which fails with a parse error
  • User convenience: DESC ecommerce is the most natural syntax
  • MySQL/PostgreSQL parity: both accept DESC <name> without qualifier

Implementation Notes

Parser change

In Parser.scala, make TABLE optional in describeTable:

def describeTable: PackratParser[DescribeTable] =
  (("DESCRIBE" | "DESC") ~ opt("TABLE")) ~ ident ^^ { case _ ~ table =>
    DescribeTable(table)
  }

Grammar ordering (critical)

In dqlStatement, the describe parsers must be reordered so that more specific forms are tried before the now-generic describeTable:

describeMaterializedView |  // DESC MATERIALIZED VIEW x — most specific
describePipeline |          // DESC PIPELINE x
describeTable |             // DESC [TABLE] x — least specific (fallback)

Without this reordering, DESC PIPELINE foo would be incorrectly captured by describeTable (treating PIPELINE as a table name).

Current order in dqlStatement

describeTable |           // line 910
...
describePipeline |        // line 914
...
describeMaterializedView  // line 919

Required order

describeMaterializedView |
describePipeline |
describeTable |

Files to modify

File Change
sql/.../parser/Parser.scala Make TABLE optional in describeTable, reorder describe parsers in dqlStatement

Tests

  • Parser unit test: DESC ecommerce parses as DescribeTable("ecommerce")
  • Parser unit test: DESC TABLE ecommerce still parses as DescribeTable("ecommerce")
  • Parser unit test: DESC PIPELINE mypipe still parses as DescribePipeline("mypipe")
  • Parser unit test: DESC MATERIALIZED VIEW myview still parses as DescribeMaterializedView("myview")

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions