tobymao / sqlglot

Python SQL Parser and Transpiler
https://sqlglot.com/
MIT License
6.59k stars 688 forks source link

Support CREATE CLUSTERED COLUMNSTORE INDEX for T-SQL #3801

Closed na399 closed 2 months ago

na399 commented 2 months ago

Is your feature request related to a problem? Please describe.

I'm trying to convert tables created by SQLMesh into columnar storage on MS SQL Server, but SQLGlot produces a ParseError on CREATE CLUSTERED COLUMNSTORE INDEX index_name ON { database_name.schema_name.table_name | schema_name.table_name | table_name }.

Describe the solution you'd like

If SQLGlot can parse this command, it would help speed up downstream model evaluation in SQLMesh a lot, and save significant storage space (approximate compression ratio 10:1).

Describe alternatives you've considered

CREATE INDEX for a normal rowstore index can be parsed successfully.

Additional context

CREATE CLUSTERED COLUMNSTORE INDEX produces a fatal error on SQLMesh: sqlmesh.utils.errors.ConfigError: Failed to parse a model definition.

When I tried to create a non-clustered columnstore index in the post-statement of SQLMesh Model, I got this warning from SQLGlot:

'@IF(@runtime_stage='evaluating', CREATE NONCLUSTERED COLUMNSTORE INDEX index_name ON foo.bar)' contains unsupported syntax. Falling back to parsing as a 'Command'. (parser.py:1474)

Although the command ran, it attempted to create the index on the final view in the destination schema foo but not the underlying table in sqlmesh__foo schema, which then failed the evaluation entirely. The macro @this_model unfortunately doesn't work on non-audit SQL models.

Thank you very much!

tobymao commented 2 months ago

can you include the documentation to the create columnstore index please?

na399 commented 2 months ago

can you include the documentation to the create columnstore index please?

https://learn.microsoft.com/en-us/sql/t-sql/statements/create-columnstore-index-transact-sql?view=sql-server-ver16

na399 commented 2 months ago

@VaggelisD You are a lifesaver! Massive thanks!