Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-24142: --no-inject-ephemeral-ctes flag for compile command #114

Merged
merged 6 commits into from
Oct 17, 2023
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
43 changes: 43 additions & 0 deletions tests/functional/adapter/ephemeral/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
fct_eph_first_sql = """
-- fct_eph_first.sql
{{ config(materialized='ephemeral') }}

with int_eph_first as(
select * from {{ ref('int_eph_first') }}
)

select * from int_eph_first
"""

int_eph_first_sql = """
-- int_eph_first.sql
{{ config(materialized='ephemeral') }}

select
1 as first_column,
2 as second_column
"""

schema_yml = """
version: 2

models:
- name: int_eph_first
columns:
- name: first_column
tests:
- not_null
- name: second_column
tests:
- not_null

- name: fct_eph_first
columns:
- name: first_column
tests:
- not_null
- name: second_column
tests:
- not_null

"""
47 changes: 47 additions & 0 deletions tests/functional/adapter/ephemeral/test_ephemeral_compilation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from dbt.contracts.graph.nodes import ModelNode
from dbt.contracts.results import RunExecutionResult, RunResult
import pytest
from dbt.tests.util import run_dbt

from tests.functional.adapter.ephemeral.fixtures import (
fct_eph_first_sql,
int_eph_first_sql,
schema_yml
)



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):
return {
"int_eph_first.sql": int_eph_first_sql,
"fct_eph_first.sql": fct_eph_first_sql,
"schema.yml": schema_yml,
}
'''
def test_ephemeral_compilation(self, project):
# Note: There are no models that run successfully. This testcase tests running tests.
results = run_dbt(["run"])
assert len(results) == 0
'''
def test__suppress_injected_ctes(self, project):
compile_output = run_dbt(
["compile", "--no-inject-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
Loading