Skip to content

Commit

Permalink
Fix: Take deployability into account when rendering a model's query w…
Browse files Browse the repository at this point in the history
…ith the 'render' command
  • Loading branch information
izeigerman committed Sep 20, 2024
1 parent 25f4760 commit fc9f8ae
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sqlmesh/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,12 +845,16 @@ def render(
)
return next(pandas_to_sql(t.cast(pd.DataFrame, df), model.columns_to_types))

snapshots = self.snapshots
deployability_index = DeployabilityIndex.create(snapshots.values())

return model.render_query_or_raise(
start=start,
end=end,
execution_time=execution_time,
snapshots=self.snapshots,
snapshots=snapshots,
expand=expand,
deployability_index=deployability_index,
engine_adapter=self.engine_adapter,
**kwargs,
)
Expand Down
39 changes: 39 additions & 0 deletions tests/core/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,45 @@ def test_render_sql_model(sushi_context, assert_exp_eq, copy_to_temp_path: t.Cal
)


@pytest.mark.slow
def test_render_non_deployable_parent(sushi_context, assert_exp_eq, copy_to_temp_path: t.Callable):
model = sushi_context.get_model("sushi.waiter_revenue_by_day")
forward_only_kind = model.kind.copy(update={"forward_only": True})
model = model.copy(update={"kind": forward_only_kind})
sushi_context.upsert_model(model)
sushi_context.plan("dev", no_prompts=True, auto_apply=True)

assert_exp_eq(
sushi_context.render(
"sushi.top_waiters",
start=date(2021, 1, 1),
end=date(2021, 1, 1),
),
"""
WITH "test_macros" AS (
SELECT
2 AS "lit_two",
"waiter_revenue_by_day"."revenue" * 2.0 AS "sql_exp",
CAST("waiter_revenue_by_day"."revenue" AS TEXT) AS "sql_lit"
FROM "memory"."sqlmesh__sushi"."sushi__waiter_revenue_by_day__32111349__temp" AS "waiter_revenue_by_day" /* memory.sushi.waiter_revenue_by_day */
)
SELECT
CAST("waiter_revenue_by_day"."waiter_id" AS INT) AS "waiter_id",
CAST("waiter_revenue_by_day"."revenue" AS DOUBLE) AS "revenue"
FROM "memory"."sqlmesh__sushi"."sushi__waiter_revenue_by_day__32111349__temp" AS "waiter_revenue_by_day" /* memory.sushi.waiter_revenue_by_day */
WHERE
"waiter_revenue_by_day"."event_date" = (
SELECT
MAX("waiter_revenue_by_day"."event_date") AS "_col_0"
FROM "memory"."sqlmesh__sushi"."sushi__waiter_revenue_by_day__32111349__temp" AS "waiter_revenue_by_day" /* memory.sushi.waiter_revenue_by_day */
)
ORDER BY
"revenue" DESC
LIMIT 10
""",
)


@pytest.mark.slow
def test_render_seed_model(sushi_context, assert_exp_eq):
assert_exp_eq(
Expand Down

0 comments on commit fc9f8ae

Please sign in to comment.