Skip to content

Commit abac8a7

Browse files
authored
fix(dlt): use timestamp macros for incremental model time filter (#5867)
Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
1 parent ffb30e4 commit abac8a7

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

sqlmesh/integrations/dlt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def generate_incremental_model(
208208
FROM
209209
{from_clause}
210210
WHERE
211-
{time_column} BETWEEN @start_ds AND @end_ds
211+
{time_column} BETWEEN @start_ts AND @end_ts
212212
"""
213213

214214

tests/cli/test_cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def test_dlt_filesystem_pipeline(tmp_path):
921921
FROM
922922
filesystem_pipeline_dataset.equipment as c
923923
WHERE
924-
TO_TIMESTAMP(CAST(c._dlt_load_id AS DOUBLE)) BETWEEN @start_ds AND @end_ds
924+
TO_TIMESTAMP(CAST(c._dlt_load_id AS DOUBLE)) BETWEEN @start_ts AND @end_ts
925925
"""
926926

927927
with open(equipment_model_path) as file:
@@ -1064,7 +1064,7 @@ def test_dlt_pipeline(runner, tmp_path):
10641064
FROM
10651065
sushi_dataset.sushi_types as c
10661066
WHERE
1067-
TO_TIMESTAMP(CAST(c._dlt_load_id AS DOUBLE)) BETWEEN @start_ds AND @end_ds
1067+
TO_TIMESTAMP(CAST(c._dlt_load_id AS DOUBLE)) BETWEEN @start_ts AND @end_ts
10681068
"""
10691069

10701070
dlt_sushi_types_model_path = tmp_path / "models/incremental_sushi_types.sql"
@@ -1095,7 +1095,7 @@ def test_dlt_pipeline(runner, tmp_path):
10951095
FROM
10961096
sushi_dataset._dlt_loads as c
10971097
WHERE
1098-
TO_TIMESTAMP(CAST(c.load_id AS DOUBLE)) BETWEEN @start_ds AND @end_ds
1098+
TO_TIMESTAMP(CAST(c.load_id AS DOUBLE)) BETWEEN @start_ts AND @end_ts
10991099
"""
11001100

11011101
with open(dlt_loads_model_path) as file:
@@ -1122,7 +1122,7 @@ def test_dlt_pipeline(runner, tmp_path):
11221122
ON
11231123
c._dlt_parent_id = p._dlt_id
11241124
WHERE
1125-
TO_TIMESTAMP(CAST(p._dlt_load_id AS DOUBLE)) BETWEEN @start_ds AND @end_ds
1125+
TO_TIMESTAMP(CAST(p._dlt_load_id AS DOUBLE)) BETWEEN @start_ts AND @end_ts
11261126
"""
11271127

11281128
with open(dlt_sushi_fillings_model_path) as file:

tests/integrations/test_dlt.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from sqlmesh.integrations.dlt import generate_incremental_model
2+
3+
4+
def test_generate_incremental_model_filters_on_timestamp_macros() -> None:
5+
# The DLT-generated model's time column is a timestamp
6+
# (TO_TIMESTAMP(...)). It must therefore be filtered with the inclusive
7+
# timestamp macros @start_ts/@end_ts, not the categorical date macros
8+
# @start_ds/@end_ds, which both render midnight and exclude any rows past
9+
# 00:00:00 on a single-day run.
10+
model = generate_incremental_model(
11+
"dataset_sqlmesh.incremental_equipment",
12+
" CAST(c.item_id AS BIGINT) AS item_id",
13+
"",
14+
"dataset.equipment",
15+
"duckdb",
16+
"c._dlt_load_id",
17+
)
18+
19+
assert "BETWEEN @start_ts AND @end_ts" in model
20+
assert "@start_ds" not in model
21+
assert "@end_ds" not in model

0 commit comments

Comments
 (0)