sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Clickhouse: Error: Failed to parse '(= toYYYYMM(time))'

Open andness opened this issue 3 months ago • 1 comments

I've hit this error from the sqlmesh run command in our staging environment, but I've also hit it at various times during development. After asking about it on Slack I was asked to see if I could reproduce. The full error is

Error: Failed to parse '(= toYYYYMM(time))' into <class 'sqlglot.expressions.PartitionedByProperty'>

I was planning to reproduce the uv run error, but since the model is INCREMENTAL_BY_TIME_RANGE the cron prevented me from using sqlmesh run. I decided to use sqlmesh destroy to start over, and that's when I hit it.

So here's what I did:

  1. Init a new sqlmesh project with the clickhouse dialect
  2. Add a single model
  3. Successfully run plan

The model contains this line:

  partitioned_by = toYYYYMM(time),

As far as I can tell this line is wrong, the correct syntax is:

  partitioned_by toYYYYMM(time),

i.e. without the =

But somehow it still gets past plan and presumably makes it into some kind of state as I'm now unable to destroy the project.

The project is now in this state locally, so if you have some instructions for what I should pull out I'll be happy to do that.

andness avatar Aug 27 '25 05:08 andness

I can confirm that after executing this:

update _snapshots set snapshot = replace(snapshot, '= toYYYYMM(time)', 'toYYYYMM(time)') where version = '3230686174';

The destroy command runs. So the problem seems to be the sql text stored in the _snapshots table.

andness avatar Aug 27 '25 05:08 andness