Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
compile --suppress-ephemeral-ctes flag, for inline compilation of mod…
…els during linting only
  • Loading branch information
benmosher committed Aug 23, 2023
commit b4b217c79c77459d428e24b8c3e8876ac9cc9184
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230823-140407.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Add --suppress-ephemeral-ctes flag for `compile` command, for usage by linting.
time: 2023-08-23T14:04:07.617476-04:00
custom:
Author: benmosher
Issue: "8480"
1 change: 1 addition & 0 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def docs_serve(ctx, **kwargs):
@p.state
@p.defer_state
@p.deprecated_state
@p.compile_suppress_ephemeral_ctes
@p.target
@p.target_path
@p.threads
Expand Down
8 changes: 8 additions & 0 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
default=True,
)

compile_suppress_ephemeral_ctes = click.option(
"--suppress-ephemeral-ctes/--no-suppress-ephemeral-ctes",
envvar="DBT_SUPPRESS_EPHEMERAL_CTES",
help="Internal flag for whether to supress injecting referenced ephemeral models' CTEs during `compile`.",
hidden=True,
default=False,
)

config_dir = click.option(
"--config-dir",
envvar=None,
Expand Down
4 changes: 4 additions & 0 deletions core/dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ def _recursively_prepend_ctes(
if model.compiled_code is None:
raise DbtRuntimeError("Cannot inject ctes into an uncompiled node", model)

flags = get_flags()
if getattr(flags, "SUPPRESS_EPHEMERAL_CTES", False):
return (model, [])

# extra_ctes_injected flag says that we've already recursively injected the ctes
if model.extra_ctes_injected:
return (model, model.extra_ctes)
Expand Down
24 changes: 22 additions & 2 deletions tests/functional/materializations/test_ephemeral_compilation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from dbt.contracts.graph.nodes import ModelNode
from dbt.contracts.results import RunExecutionResult, RunResult
import pytest
from dbt.tests.util import run_dbt

Expand Down Expand Up @@ -53,6 +55,16 @@
"""


SUPPRESSED_CTE_EXPECTED_OUTPUT = """-- fct_eph_first.sql


with int_eph_first as(
select * from __dbt__cte__int_eph_first
)

select * from int_eph_first"""


class TestEphemeralCompilation:
@pytest.fixture(scope="class")
def models(self):
Expand All @@ -67,5 +79,13 @@ def test_ephemeral_compilation(self, project):
results = run_dbt(["run"])
assert len(results) == 0

results = run_dbt(["test"])
len(results) == 4
def test__suppress_injected_ctes(self, project):
compile_output = run_dbt(
["compile", "--suppress-ephemeral-ctes", "--select", "fct_eph_first"]
)
assert isinstance(compile_output, RunExecutionResult)
node_result = compile_output.results[0]
assert isinstance(node_result, RunResult)
node = node_result.node
assert isinstance(node, ModelNode)
assert node.compiled_code == SUPPRESSED_CTE_EXPECTED_OUTPUT