Skip to content

Commit

Permalink
update MV tests
Browse files Browse the repository at this point in the history
Provide a custom schema to make sure that the full target table
name (schema + relation name) is included in the CREATE MATERIALIZED
VIEW statement
  • Loading branch information
SoryRawyer committed Jan 25, 2024
1 parent d55f4d4 commit f449300
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
materialized='materialized_view',
engine='MergeTree()',
order_by='(id)',
schema='custom_schema',
) }}
{% if var('run_type', '') == '' %}
Expand Down Expand Up @@ -92,6 +93,7 @@ def test_create(self, project):
2. create a model as a materialized view, selecting from the table created in (1)
3. insert data into the base table and make sure it's there in the target table created in (2)
"""
schema = quote_identifier(project.test_schema + "_custom_schema")
results = run_dbt(["seed"])
assert len(results) == 1
columns = project.run_sql("DESCRIBE TABLE people", fetch="all")
Expand All @@ -101,10 +103,10 @@ def test_create(self, project):
results = run_dbt()
assert len(results) == 1

columns = project.run_sql("DESCRIBE TABLE hackers", fetch="all")
columns = project.run_sql(f"DESCRIBE TABLE {schema}.hackers", fetch="all")
assert columns[0][1] == "Int32"

columns = project.run_sql("DESCRIBE hackers_mv", fetch="all")
columns = project.run_sql(f"DESCRIBE {schema}.hackers_mv", fetch="all")
assert columns[0][1] == "Int32"

check_relation_types(
Expand All @@ -123,7 +125,7 @@ def test_create(self, project):
"""
)

result = project.run_sql("select count(*) from hackers", fetch="all")
result = project.run_sql(f"select count(*) from {schema}.hackers", fetch="all")
assert result[0][0] == 4


Expand All @@ -145,6 +147,7 @@ def models(self):
}

def test_update(self, project):
schema = quote_identifier(project.test_schema + "_custom_schema")
# create our initial materialized view
run_dbt(["seed"])
run_dbt()
Expand All @@ -162,6 +165,6 @@ def test_update(self, project):

# assert that we now have both of Dade's aliases in our hackers table
result = project.run_sql(
"select distinct hacker_alias from hackers where name = 'Dade'", fetch="all"
f"select distinct hacker_alias from {schema}.hackers where name = 'Dade'", fetch="all"
)
assert len(result) == 2

0 comments on commit f449300

Please sign in to comment.