diff --git a/tests/functional/compile/fixtures.py b/tests/functional/compile/fixtures.py index e0be7c895bf..97ccd6d16b6 100644 --- a/tests/functional/compile/fixtures.py +++ b/tests/functional/compile/fixtures.py @@ -42,6 +42,15 @@ select sum(n) from t; """ +first_ephemeral_model_with_alias_sql = """ +{{ config(materialized = 'ephemeral', alias = 'first_alias') }} +select 1 as fun +""" + +second_ephemeral_model_with_alias_sql = """ +select * from {{ ref('first_ephemeral_model_with_alias') }} +""" + schema_yml = """ version: 2 diff --git a/tests/functional/compile/test_compile.py b/tests/functional/compile/test_compile.py index e7732b09a8c..eaa61d5d8a4 100644 --- a/tests/functional/compile/test_compile.py +++ b/tests/functional/compile/test_compile.py @@ -10,10 +10,12 @@ from tests.functional.assertions.test_runner import dbtTestRunner from tests.functional.compile.fixtures import ( first_ephemeral_model_sql, + first_ephemeral_model_with_alias_sql, first_model_sql, model_multiline_jinja, schema_yml, second_ephemeral_model_sql, + second_ephemeral_model_with_alias_sql, second_model_sql, third_ephemeral_model_sql, with_recursive_model_sql, @@ -128,6 +130,25 @@ def test_with_recursive_cte(self, project): ] +class TestEphemeralModelWithAlias: + @pytest.fixture(scope="class") + def models(self): + return { + "first_ephemeral_model_with_alias.sql": first_ephemeral_model_with_alias_sql, + "second_ephemeral_model_with_alias.sql": second_ephemeral_model_with_alias_sql, + } + + def test_compile(self, project): + run_dbt(["compile"]) + + assert get_lines("second_ephemeral_model_with_alias") == [ + "with __dbt__cte__first_alias as (", + "select 1 as fun", + ")", + "select * from __dbt__cte__first_alias", + ] + + class TestCompile: @pytest.fixture(scope="class") def models(self): diff --git a/tests/functional/schema/fixtures/sql.py b/tests/functional/schema/fixtures/sql.py index daed6d0c741..ca9fe2a0cdf 100644 --- a/tests/functional/schema/fixtures/sql.py +++ b/tests/functional/schema/fixtures/sql.py @@ -18,15 +18,7 @@ ) _TABLE_TWO_DOT_MODEL_SCHEMA = "second_schema" _TABLE_TWO_DOT_MODEL_NAME = f"{_TABLE_TWO_DOT_MODEL_SCHEMA}.view_2" -_TABLE_TWO_DOT_MODEL = ( - """ -{{ config(materialized='ephemeral') }} - -select * from {{ ref('""" - + _TABLE_ONE_DOT_MODEL_NAME - + """') }} -""" -) +_TABLE_TWO_DOT_MODEL = "select * from {{ ref('" + _TABLE_ONE_DOT_MODEL_NAME + "') }}" _TABLE_THREE_SCHEMA = "test" _TABLE_THREE = ( diff --git a/tests/functional/schema/test_custom_schema.py b/tests/functional/schema/test_custom_schema.py index 5a9999abbde..5a9969e4284 100644 --- a/tests/functional/schema/test_custom_schema.py +++ b/tests/functional/schema/test_custom_schema.py @@ -17,6 +17,7 @@ _TABLE_TWO, _TABLE_TWO_DOT_MODEL, _TABLE_TWO_DOT_MODEL_NAME, + _TABLE_TWO_DOT_MODEL_SCHEMA, _TABLE_TWO_SCHEMA, _VALIDATION_SQL, ) @@ -201,15 +202,18 @@ def test__postgres__custom_schema_from_model_name( project.run_sql(_VALIDATION_SQL) run_dbt(["seed"]) results = run_dbt(["run"]) - # Model 2 is ephemeral, so it should not show up in the results list - assert len(results) == 2 + assert len(results) == 3 table_results = {r.node.name: r.node.schema for r in results.results} assert table_results[_TABLE_ONE_DOT_MODEL_NAME] == _TABLE_ONE_DOT_MODEL_SCHEMA + assert table_results[_TABLE_TWO_DOT_MODEL_NAME] == _TABLE_TWO_DOT_MODEL_SCHEMA assert table_results["table_3"] == f"{project.test_schema}" check_relations_equal( adapter=project.adapter, relation_names=("seed", _TABLE_ONE_DOT_MODEL_NAME) ) + check_relations_equal( + adapter=project.adapter, relation_names=("seed", _TABLE_TWO_DOT_MODEL_NAME) + ) check_relations_equal( adapter=project.adapter, relation_names=("agg", f"{project.test_schema}.table_3") )