-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Don't overwrite sql in extra_ctes when compiling (rendering) nodes (cherry picked from commit 70c26f5) Co-authored-by: Gerda Shank <[email protected]>
- Loading branch information
1 parent
ec17ece
commit f23dbb6
Showing
6 changed files
with
122 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Fixes | ||
body: Fix compilation logic for ephemeral nodes | ||
time: 2023-02-21T17:06:30.218568-05:00 | ||
custom: | ||
Author: gshank | ||
Issue: "6885" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
tests/functional/materializations/test_ephemeral_compilation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt | ||
|
||
# Note: This tests compilation only, so is a dbt Core test and not an adapter test. | ||
# There is some complicated logic in core/dbt/compilation.py having to do with | ||
# ephemeral nodes and handling multiple threads at the same time. This test | ||
# fails fairly regularly if that is broken, but does occasionally work (depending | ||
# on the order in which things are compiled). It requires multi-threading to fail. | ||
|
||
|
||
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 | ||
""" | ||
|
||
|
||
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 | ||
|
||
results = run_dbt(["test"]) | ||
len(results) == 4 |