Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sqlmesh/core/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import typing as t
from contextlib import contextmanager
from datetime import timedelta
from functools import partial
from pathlib import Path

Expand Down Expand Up @@ -83,12 +84,12 @@ def _render(
runtime_stage: RuntimeStage = RuntimeStage.LOADING,
**kwargs: t.Any,
) -> t.List[t.Optional[exp.Expression]]:
"""Renders a expression, expanding macros with provided kwargs
"""Renders an expression, expanding macros with provided kwargs

Args:
start: The start datetime to render. Defaults to epoch start.
end: The end datetime to render. Defaults to epoch start.
execution_time: The date/time time reference to use for execution time.
execution_time: The datetime/time reference to use for execution time.
snapshots: All upstream snapshots (by model name) to use for expansion and mapping of physical locations.
table_mapping: Table mapping of physical locations. Takes precedence over snapshot mappings.
deployability_index: Determines snapshots that are deployable in the context of this evaluation.
Expand Down Expand Up @@ -173,7 +174,7 @@ def _resolve_table(table: str | exp.Table) -> str:
)

start_time, end_time = (
make_inclusive(start or c.EPOCH, end or c.EPOCH, self._dialect)
make_inclusive(start or c.EPOCH, end or c.EPOCH + timedelta(days=1), self._dialect)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the only place where we use epoch as a placeholder. I wonder whether we should instead have 3 constants:

START_PLACEHOLDER
END_PLACEHOLDER
EXECUTION_TIME_PLACEHOLDER

and use these instead throughout.

if not self._only_execution_time
else (None, None)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def test_condition_with_macro_var(model: Model):
)
assert (
rendered_query.sql(dialect="duckdb")
== """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)"""
== """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)"""
)


Expand Down
1 change: 1 addition & 0 deletions tests/core/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ def test_environment_statements_config(tmp_path):
def test_pydantic_import_error() -> None:
class TestConfig(DuckDBConnectionConfig):
pass
TestConfig.model_rebuild()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to fix a local issue here but didn't completely fix it.


TestConfig()

Expand Down
34 changes: 32 additions & 2 deletions tests/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ def test_render_query(assert_exp_eq, sushi_context):
CAST("o"."event_date" AS DATE) AS "event_date"
FROM "memory"."sushi"."orders" AS "o"
WHERE
"o"."event_date" <= CAST('1970-01-01' AS DATE) AND "o"."event_date" >= CAST('1970-01-01' AS DATE)
"o"."event_date" <= CAST('1970-01-02' AS DATE) AND "o"."event_date" >= CAST('1970-01-01' AS DATE)
""",
)

Expand Down Expand Up @@ -2261,6 +2261,36 @@ def test_render_query(assert_exp_eq, sushi_context):
)


def test_render_temporal_variables_give_different_hashes(sushi_context):
model_with_start = SqlModel(
name="test",
cron="1 0 * * *",
kind=IncrementalByTimeRangeKind(time_column=TimeColumn(column="y")),
query=d.parse_one(
"""
SELECT y
FROM x
WHERE
y = @start_ds
"""
),
)
model_with_end = SqlModel(
name="test",
cron="1 0 * * *",
kind=IncrementalByTimeRangeKind(time_column=TimeColumn(column="y")),
query=d.parse_one(
"""
SELECT y
FROM x
WHERE
y = @end_ds
"""
),
)
assert model_with_start.data_hash != model_with_end.data_hash


def test_time_column():
expressions = d.parse(
"""
Expand Down Expand Up @@ -2478,7 +2508,7 @@ def test_parse(assert_exp_eq):
"ds" AS "ds"
FROM "x" AS "x"
WHERE
"ds" BETWEEN '1970-01-01' AND '1970-01-01'
"ds" BETWEEN '1970-01-01' AND '1970-01-02'
""",
)

Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_snapshot_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ def test_migrate_missing_table(mocker: MockerFixture, make_snapshot):
[
call('CREATE TABLE "pre" ("a" INT)'),
call(
'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'
'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'
),
call('DROP TABLE "pre"'),
]
Expand Down
2 changes: 1 addition & 1 deletion tests/web/test_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_get_lineage(client: TestClient, web_sushi_context: Context) -> None:
CAST("o"."event_date" AS DATE) AS "event_date"
FROM "memory"."sushi"."orders" AS "o"
WHERE
"o"."event_date" <= CAST('1970-01-01' AS DATE)
"o"."event_date" <= CAST('1970-01-02' AS DATE)
AND "o"."event_date" >= CAST('1970-01-01' AS DATE)""",
"expression": 'CAST("o"."event_date" AS DATE) AS "event_date"',
"models": {'"memory"."sushi"."orders"': ["event_date"]},
Expand Down