Skip to content

Commit c76c9ef

Browse files
author
Noel Gomez
committed
dynamic tables update
1 parent ce49b1e commit c76c9ef

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

transform/dbt_project.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,16 @@ models:
135135
+transient: "{{ 'false' if target.name == 'prd' else 'true' }}"
136136
copy_grants: true
137137

138+
# This creates a view in snowflake that will track failures. Usefull for dynamic tables dbt isnt refreshing
139+
# Run dbt with: --vars '{"persist_tests": "true", "tests_model": "test_failures"}'
138140
on-run-end:
139141
- "{{ create_test_failure_view(results) }}"
140142

141-
143+
# In development, this will be created in your user schema
142144
data_tests:
143145
+store_failures: true
144146
+schema: DBT_TEST__AUDIT
147+
+store_failures_as: view
145148

146149
vars:
147150
'dbt_date:time_zone': 'America/Los_Angeles'

transform/macros/tooling/create_test_failure_view.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
where 1 = 0
1515
#}
1616

17+
{# dbt must be wirh with --vars '{"persist_tests": "true", "tests_model": "test_failures"}' #}
18+
1719
{% macro create_test_failure_view(results) -%}
18-
{%- if execute -%}
20+
{% if execute and var('persist_tests', 'false') == 'true' %}
1921
{% set test_failures_unique_id = "model." ~ project_name ~ ".stg_test_failures" %}
2022
{% set test_selects = [] %}
2123
{% set test_failures_node = graph.nodes[test_failures_unique_id] %}

visualize/streamlit/loans-example/example.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,17 @@ select * from balboa.l3_loan_analytics.loans_by_state order by NUMBER_OF_LOANS d
8080

8181
select * from balboa_dev.gomezn.loans_by_state__standard;
8282
select * from balboa_dev.gomezn.loans_by_state__dynamic;
83+
84+
85+
SELECT table_catalog,
86+
table_schema,
87+
table_name,
88+
is_dynamic
89+
FROM BALBOA.INFORMATION_SCHEMA.TABLES
90+
WHERE is_dynamic = 'YES';
91+
92+
-- Grant access to all existing dynamic tables in a schema
93+
GRANT SELECT ON ALL DYNAMIC TABLES IN DATABASE BALBOA TO ROLE CATALOG;
94+
95+
-- For future dynamic tables, you'll want to grant future privileges
96+
GRANT SELECT ON FUTURE DYNAMIC TABLES IN DATABASE BALBOA TO ROLE CATALOG;

0 commit comments

Comments
 (0)