Skip to content

Commit 8ed6fd0

Browse files
committed
update default value for end_time to be +1 day
1 parent e07c5fe commit 8ed6fd0

File tree

6 files changed

+40
-8
lines changed

6 files changed

+40
-8
lines changed

sqlmesh/core/renderer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import typing as t
55
from contextlib import contextmanager
6+
from datetime import timedelta
67
from functools import partial
78
from pathlib import Path
89

@@ -83,12 +84,12 @@ def _render(
8384
runtime_stage: RuntimeStage = RuntimeStage.LOADING,
8485
**kwargs: t.Any,
8586
) -> t.List[t.Optional[exp.Expression]]:
86-
"""Renders a expression, expanding macros with provided kwargs
87+
"""Renders an expression, expanding macros with provided kwargs
8788
8889
Args:
8990
start: The start datetime to render. Defaults to epoch start.
9091
end: The end datetime to render. Defaults to epoch start.
91-
execution_time: The date/time time reference to use for execution time.
92+
execution_time: The datetime/time reference to use for execution time.
9293
snapshots: All upstream snapshots (by model name) to use for expansion and mapping of physical locations.
9394
table_mapping: Table mapping of physical locations. Takes precedence over snapshot mappings.
9495
deployability_index: Determines snapshots that are deployable in the context of this evaluation.
@@ -173,7 +174,7 @@ def _resolve_table(table: str | exp.Table) -> str:
173174
)
174175

175176
start_time, end_time = (
176-
make_inclusive(start or c.EPOCH, end or c.EPOCH, self._dialect)
177+
make_inclusive(start or c.EPOCH, end or c.EPOCH + timedelta(days=1), self._dialect)
177178
if not self._only_execution_time
178179
else (None, None)
179180
)

tests/core/test_audit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def test_condition_with_macro_var(model: Model):
809809
)
810810
assert (
811811
rendered_query.sql(dialect="duckdb")
812-
== """SELECT * FROM (SELECT * FROM "db"."test_model" AS "test_model" WHERE "ds" BETWEEN '1970-01-01' AND '1970-01-01') AS "_q_0" WHERE "x" IS NULL AND "dt" BETWEEN CAST('1970-01-01 00:00:00+00:00' AS TIMESTAMPTZ) AND CAST('1970-01-01 23:59:59.999999+00:00' AS TIMESTAMPTZ)"""
812+
== """SELECT * FROM (SELECT * FROM "db"."test_model" AS "test_model" WHERE "ds" BETWEEN '1970-01-01' AND '1970-01-01') AS "_q_0" WHERE "x" IS NULL AND "dt" BETWEEN CAST('1970-01-01 00:00:00+00:00' AS TIMESTAMPTZ) AND CAST('1970-01-02 23:59:59.999999+00:00' AS TIMESTAMPTZ)"""
813813
)
814814

815815

tests/core/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ def test_environment_statements_config(tmp_path):
990990
def test_pydantic_import_error() -> None:
991991
class TestConfig(DuckDBConnectionConfig):
992992
pass
993+
TestConfig.model_rebuild()
993994

994995
TestConfig()
995996

tests/core/test_model.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ def test_render_query(assert_exp_eq, sushi_context):
21612161
CAST("o"."event_date" AS DATE) AS "event_date"
21622162
FROM "memory"."sushi"."orders" AS "o"
21632163
WHERE
2164-
"o"."event_date" <= CAST('1970-01-01' AS DATE) AND "o"."event_date" >= CAST('1970-01-01' AS DATE)
2164+
"o"."event_date" <= CAST('1970-01-02' AS DATE) AND "o"."event_date" >= CAST('1970-01-01' AS DATE)
21652165
""",
21662166
)
21672167

@@ -2261,6 +2261,36 @@ def test_render_query(assert_exp_eq, sushi_context):
22612261
)
22622262

22632263

2264+
def test_render_temporal_variables_give_different_hashes(sushi_context):
2265+
model_with_start = SqlModel(
2266+
name="test",
2267+
cron="1 0 * * *",
2268+
kind=IncrementalByTimeRangeKind(time_column=TimeColumn(column="y")),
2269+
query=d.parse_one(
2270+
"""
2271+
SELECT y
2272+
FROM x
2273+
WHERE
2274+
y = @start_ds
2275+
"""
2276+
),
2277+
)
2278+
model_with_end = SqlModel(
2279+
name="test",
2280+
cron="1 0 * * *",
2281+
kind=IncrementalByTimeRangeKind(time_column=TimeColumn(column="y")),
2282+
query=d.parse_one(
2283+
"""
2284+
SELECT y
2285+
FROM x
2286+
WHERE
2287+
y = @end_ds
2288+
"""
2289+
),
2290+
)
2291+
assert model_with_start.data_hash != model_with_end.data_hash
2292+
2293+
22642294
def test_time_column():
22652295
expressions = d.parse(
22662296
"""
@@ -2478,7 +2508,7 @@ def test_parse(assert_exp_eq):
24782508
"ds" AS "ds"
24792509
FROM "x" AS "x"
24802510
WHERE
2481-
"ds" BETWEEN '1970-01-01' AND '1970-01-01'
2511+
"ds" BETWEEN '1970-01-01' AND '1970-01-02'
24822512
""",
24832513
)
24842514

tests/core/test_snapshot_evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ def test_migrate_missing_table(mocker: MockerFixture, make_snapshot):
12371237
[
12381238
call('CREATE TABLE "pre" ("a" INT)'),
12391239
call(
1240-
'CREATE TABLE IF NOT EXISTS "sqlmesh__test_schema"."test_schema__test_model__1" AS SELECT "c" AS "c", "a" AS "a" FROM "tbl" AS "tbl" WHERE "ds" BETWEEN \'1970-01-01\' AND \'1970-01-01\' AND FALSE LIMIT 0'
1240+
'CREATE TABLE IF NOT EXISTS "sqlmesh__test_schema"."test_schema__test_model__1" AS SELECT "c" AS "c", "a" AS "a" FROM "tbl" AS "tbl" WHERE "ds" BETWEEN \'1970-01-01\' AND \'1970-01-02\' AND FALSE LIMIT 0'
12411241
),
12421242
call('DROP TABLE "pre"'),
12431243
]

tests/web/test_lineage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_get_lineage(client: TestClient, web_sushi_context: Context) -> None:
2525
CAST("o"."event_date" AS DATE) AS "event_date"
2626
FROM "memory"."sushi"."orders" AS "o"
2727
WHERE
28-
"o"."event_date" <= CAST('1970-01-01' AS DATE)
28+
"o"."event_date" <= CAST('1970-01-02' AS DATE)
2929
AND "o"."event_date" >= CAST('1970-01-01' AS DATE)""",
3030
"expression": 'CAST("o"."event_date" AS DATE) AS "event_date"',
3131
"models": {'"memory"."sushi"."orders"': ["event_date"]},

0 commit comments

Comments
 (0)