-
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
* Update catalog macro & add tests * [#3961] Enable cataloging of unlogged Postgres tables * Update contributors and add new lines to test
- Loading branch information
Sam Lader
authored
Oct 6, 2021
1 parent
6fc64f0
commit 91b43f7
Showing
5 changed files
with
76 additions
and
1 deletion.
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
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
8 changes: 8 additions & 0 deletions
8
test/integration/074_postgres_unlogged_table_tests/models/schema.yml
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,8 @@ | ||
version: 2 | ||
models: | ||
- name: table_unlogged | ||
description: "Unlogged table model" | ||
columns: | ||
- name: column_a | ||
description: "Sample description" | ||
quote: true |
3 changes: 3 additions & 0 deletions
3
test/integration/074_postgres_unlogged_table_tests/models/table_unlogged.sql
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,3 @@ | ||
{{ config(materialized = 'table', unlogged = True) }} | ||
|
||
select 1 as column_a |
62 changes: 62 additions & 0 deletions
62
test/integration/074_postgres_unlogged_table_tests/test_postgres_unlogged_table.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,62 @@ | ||
import re | ||
import json | ||
from test.integration.base import DBTIntegrationTest, use_profile | ||
|
||
|
||
class TestPostgresUnloggedTable(DBTIntegrationTest): | ||
@property | ||
def schema(self): | ||
return "postgres_unlogged_074" | ||
|
||
@property | ||
def models(self): | ||
return "models" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
'config-version': 2, | ||
'models': { | ||
'test': { | ||
'materialized': 'table', | ||
'+persist_docs': { | ||
"relation": True, | ||
"columns": True, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
@use_profile('postgres') | ||
def test__postgres__unlogged__table__catalog(self): | ||
table_name = 'table_unlogged' | ||
|
||
results = self.run_dbt(['run', '--models', table_name]) | ||
self.assertEqual(len(results), 1) | ||
|
||
assert self.get_table_persistence(table_name) == 'u' | ||
|
||
self.run_dbt(['docs', 'generate']) | ||
|
||
with open('target/catalog.json') as fp: | ||
catalog_data = json.load(fp) | ||
|
||
assert len(catalog_data['nodes']) == 1 | ||
|
||
table_node = catalog_data['nodes'][f'model.test.{table_name}'] | ||
assert 'column_a' in table_node['columns'] | ||
|
||
def get_table_persistence(self, table_name): | ||
sql = """ | ||
SELECT | ||
relpersistence | ||
FROM pg_class | ||
WHERE relname = '{table_name}' | ||
""" | ||
sql = sql.format(table_name=table_name, schema=self.unique_schema()) | ||
|
||
result, = self.run_sql(sql, fetch='one') | ||
|
||
self.assertEqual(len(result), 1) | ||
|
||
return result |