Skip to content
Merged
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
2 changes: 1 addition & 1 deletion sqlmesh/dbt/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def create_builtin_globals(
builtin_globals["var"] = Var(variables)

snapshot = jinja_globals.pop("snapshot", None)
is_incremental = bool(snapshot.intervals) if snapshot else False
is_incremental = bool(snapshot.intervals) and snapshot.is_incremental if snapshot else False
builtin_globals["is_incremental"] = lambda: is_incremental

builtin_globals["builtins"] = AttributeDict(
Expand Down
27 changes: 27 additions & 0 deletions tests/dbt/test_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,13 +1125,40 @@ def test_is_incremental(sushi_test_project: Project, assert_exp_eq, mocker):

snapshot = mocker.Mock()
snapshot.intervals = [1]
snapshot.is_incremental = True

assert_exp_eq(
model_config.to_sqlmesh(context).render_query_or_raise(snapshot=snapshot).sql(),
'SELECT 1 AS "one" FROM "tbl_a" AS "tbl_a" WHERE "ds" > (SELECT MAX("ds") FROM "model" AS "model")',
)


@pytest.mark.xdist_group("dbt_manifest")
def test_is_incremental_non_incremental_model(sushi_test_project: Project, assert_exp_eq, mocker):
model_config = ModelConfig(
name="model",
package_name="package",
schema="sushi",
alias="some_table",
sql="""
SELECT 1 AS one FROM tbl_a
{% if is_incremental() %}
WHERE ds > (SELECT MAX(ds) FROM model)
{% endif %}
""",
)
context = sushi_test_project.context

snapshot = mocker.Mock()
snapshot.intervals = [1]
snapshot.is_incremental = False

assert_exp_eq(
model_config.to_sqlmesh(context).render_query_or_raise(snapshot=snapshot).sql(),
'SELECT 1 AS "one" FROM "tbl_a" AS "tbl_a"',
)


@pytest.mark.xdist_group("dbt_manifest")
def test_dbt_max_partition(sushi_test_project: Project, assert_exp_eq, mocker: MockerFixture):
model_config = ModelConfig(
Expand Down