sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Comment at end of model script results in model query to be included in post statements

Open blecourt-private opened this issue 8 months ago • 0 comments

Having a comment at the end of a model script results in model query to be included in post statements in the snapshot metadata.

SQLMesh version: 0.176.0

Reproducible example

Using the scaffolded example created by sqlmesh init duckdb.

Then adding a comment to the file models/incremental_model.sql:

MODEL (
  name sqlmesh_example.incremental_model,
  kind INCREMENTAL_BY_TIME_RANGE (
    time_column event_date
  ),
  start '2020-01-01',
  cron '@daily',
  grain (id, event_date)
);

SELECT
  id,
  item_id,
  event_date
FROM sqlmesh_example.seed_model
WHERE
  event_date BETWEEN @start_date AND @end_date
;

--Just a comment

Then I did sqlmesh plan.

Inspecting the snapshots in the statestore reveils the following in the snapshot column (for "db"."sqlmesh_example"."incremental_model"):

...
    "pre_statements": [],
    "post_statements": [
      "SELECT\n  id,\n  item_id,\n  event_date\nFROM sqlmesh_example.seed_model\nWHERE\n  event_date BETWEEN @start_date AND @end_date\n;"
    ],
    "on_virtual_update": [],
    "query": "SELECT\n  id,\n  item_id,\n  event_date\nFROM sqlmesh_example.seed_model\nWHERE\n  event_date BETWEEN @start_date AND @end_date\n;",
    "source_type": "sql"
...

Without the comment the result is

    "pre_statements": [],
    "post_statements": [],
    "on_virtual_update": [],
    "query": "SELECT\n  id,\n  item_id,\n  event_date\nFROM sqlmesh_example.seed_model\nWHERE\n  event_date BETWEEN @start_date AND @end_date\n;",
    "source_type": "sql"

blecourt-private avatar Apr 25 '25 14:04 blecourt-private