Skip to content

Commit f32fb81

Browse files
committed
Disable sqlglot optimization for dbt projects
1 parent a5fd075 commit f32fb81

File tree

5 files changed

+16
-38
lines changed

5 files changed

+16
-38
lines changed

.circleci/continue_config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ workflows:
300300
name: cloud_engine_<< matrix.engine >>
301301
context:
302302
- sqlmesh_cloud_database_integration
303-
requires:
304-
- engine_tests_docker
303+
# requires:
304+
# - engine_tests_docker
305305
matrix:
306306
parameters:
307307
engine:
@@ -313,10 +313,10 @@ workflows:
313313
- athena
314314
- fabric
315315
- gcp-postgres
316-
filters:
317-
branches:
318-
only:
319-
- main
316+
# filters:
317+
# branches:
318+
# only:
319+
# - main
320320
- ui_style
321321
- ui_test
322322
- vscode_test

sqlmesh/dbt/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,10 @@ def to_sqlmesh(
739739
)
740740
else:
741741
model_kwargs["start"] = begin
742-
# If user explicitly disables concurrent batches then we want to set depends on past to true which we
743-
# will do by including the model in the depends_on
742+
# If user explicitly disables concurrent batches then force sequential execution by setting batch_concurrency to 1
744743
if self.concurrent_batches is not None and self.concurrent_batches is False:
745-
depends_on = model_kwargs.get("depends_on", set())
746-
depends_on.add(self.canonical_name(context))
744+
if hasattr(kind, "batch_concurrency"):
745+
kind.batch_concurrency = 1
747746

748747
model_kwargs["start"] = model_kwargs.get(
749748
"start", context.sqlmesh_config.model_defaults.start
@@ -762,6 +761,7 @@ def to_sqlmesh(
762761
allow_partials=allow_partials,
763762
virtual_environment_mode=virtual_environment_mode,
764763
dbt_node_info=self.node_info,
764+
optimize_query=False,
765765
**optional_kwargs,
766766
**model_kwargs,
767767
)

tests/core/integration/test_dbt.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import typing as t
44
import pytest
5-
from sqlmesh.core.model.common import ParsableSql
65
import time_machine
76

87
from sqlmesh.core.context import Context
@@ -11,7 +10,6 @@
1110
)
1211
from sqlmesh.core.snapshot import (
1312
DeployabilityIndex,
14-
SnapshotChangeCategory,
1513
)
1614

1715
if t.TYPE_CHECKING:
@@ -20,27 +18,6 @@
2018
pytestmark = pytest.mark.slow
2119

2220

23-
@time_machine.travel("2023-01-08 15:00:00 UTC")
24-
def test_dbt_select_star_is_directly_modified(sushi_test_dbt_context: Context):
25-
context = sushi_test_dbt_context
26-
27-
model = context.get_model("sushi.simple_model_a")
28-
context.upsert_model(
29-
model,
30-
query_=ParsableSql(sql="SELECT 1 AS a, 2 AS b"),
31-
)
32-
33-
snapshot_a_id = context.get_snapshot("sushi.simple_model_a").snapshot_id # type: ignore
34-
snapshot_b_id = context.get_snapshot("sushi.simple_model_b").snapshot_id # type: ignore
35-
36-
plan = context.plan_builder("dev", skip_tests=True).build()
37-
assert plan.directly_modified == {snapshot_a_id, snapshot_b_id}
38-
assert {i.snapshot_id for i in plan.missing_intervals} == {snapshot_a_id, snapshot_b_id}
39-
40-
assert plan.snapshots[snapshot_a_id].change_category == SnapshotChangeCategory.NON_BREAKING
41-
assert plan.snapshots[snapshot_b_id].change_category == SnapshotChangeCategory.NON_BREAKING
42-
43-
4421
@time_machine.travel("2023-01-08 15:00:00 UTC")
4522
def test_dbt_is_incremental_table_is_missing(sushi_test_dbt_context: Context):
4623
context = sushi_test_dbt_context

tests/core/integration/test_multi_repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def test_multi_hybrid(mocker):
413413
sqlmesh_rendered = (
414414
'SELECT "e"."col_a" AS "col_a", "e"."col_b" AS "col_b" FROM "memory"."dbt_repo"."e" AS "e"'
415415
)
416-
dbt_rendered = 'SELECT DISTINCT ROUND(CAST(("b"."col_a" / NULLIF(100, 0)) AS DECIMAL(16, 2)), 2) AS "rounded_col_a" FROM "memory"."sqlmesh_repo"."b" AS "b"'
416+
dbt_rendered = 'SELECT DISTINCT ROUND(CAST(("col_a" / NULLIF(100, 0)) AS DECIMAL(16, 2)), 2) AS "rounded_col_a" FROM "memory"."sqlmesh_repo"."b" AS "b"'
417417
assert sqlmesh_model_a.render_query().sql() == sqlmesh_rendered
418418
assert dbt_model_c.render_query().sql() == dbt_rendered
419419

tests/dbt/test_model.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ def test_load_microbatch_all_defined_diff_values(
369369
column=exp.to_column("blah", quoted=True), format="%Y-%m-%d"
370370
)
371371
assert model.kind.batch_size == 1
372-
assert model.depends_on_self is True
372+
assert model.kind.batch_concurrency == 1
373+
assert model.depends_on_self is False
373374

374375

375376
@pytest.mark.slow
@@ -625,7 +626,7 @@ def test_load_microbatch_with_ref(
625626
)
626627
assert (
627628
context.render(microbatch_two_snapshot_fqn, start="2025-01-01", end="2025-01-10").sql()
628-
== 'SELECT "_q_0"."cola" AS "cola", "_q_0"."ds" AS "ds" FROM (SELECT "microbatch"."cola" AS "cola", "microbatch"."ds" AS "ds" FROM "local"."main"."microbatch" AS "microbatch" WHERE "microbatch"."ds" < \'2025-01-11 00:00:00+00:00\' AND "microbatch"."ds" >= \'2025-01-01 00:00:00+00:00\') AS "_q_0"'
629+
== 'SELECT "cola" AS "cola", "ds" AS "ds" FROM (SELECT * FROM "local"."main"."microbatch" AS "microbatch" WHERE "ds" >= \'2025-01-01 00:00:00+00:00\' AND "ds" < \'2025-01-11 00:00:00+00:00\') AS "_q_0"'
629630
)
630631

631632

@@ -691,7 +692,7 @@ def test_load_microbatch_with_ref_no_filter(
691692
)
692693
assert (
693694
context.render(microbatch_two_snapshot_fqn, start="2025-01-01", end="2025-01-10").sql()
694-
== 'SELECT "microbatch"."cola" AS "cola", "microbatch"."ds" AS "ds" FROM "local"."main"."microbatch" AS "microbatch"'
695+
== 'SELECT "cola" AS "cola", "ds" AS "ds" FROM "local"."main"."microbatch" AS "microbatch"'
695696
)
696697

697698

@@ -1076,7 +1077,7 @@ def test_conditional_ref_in_unexecuted_branch(copy_to_temp_path: t.Callable):
10761077
assert rendered is not None
10771078
assert (
10781079
rendered.sql()
1079-
== 'WITH "source" AS (SELECT "simple_model_a"."a" AS "a" FROM "memory"."sushi"."simple_model_a" AS "simple_model_a") SELECT "source"."a" AS "a" FROM "source" AS "source"'
1080+
== 'WITH "source" AS (SELECT * FROM "memory"."sushi"."simple_model_a" AS "simple_model_a") SELECT * FROM "source" AS "source"'
10801081
)
10811082

10821083
# And run plan with this conditional model for good measure

0 commit comments

Comments
 (0)