Skip to content

Commit

Permalink
Merge pull request #114 from Teradata/MT255026_IDE-24142_1.6.x
Browse files Browse the repository at this point in the history
IDE-24142: --no-inject-ephemeral-ctes flag for compile command
  • Loading branch information
tallamohan authored Oct 17, 2023
2 parents f99d807 + 6b5a2bb commit e6fb554
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
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

0 comments on commit e6fb554

Please sign in to comment.