-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from fishtown-analytics/feature/get_relations…
…_by_schema_prefix feature/get relations by schema prefix
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 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
4 changes: 4 additions & 0 deletions
4
integration_tests/models/sql/test_get_relations_by_pattern.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,4 @@ | ||
{{ config(materialized = 'table') }} | ||
|
||
{% set relations = dbt_utils.get_relations_by_pattern(target.schema, 'data_events_') %} | ||
{{ dbt_utils.union_relations(relations) }} |
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,23 @@ | ||
{% macro get_relations_by_pattern(schema_pattern, table_pattern, exclude='', database=target.database) %} | ||
|
||
{%- call statement('get_tables', fetch_result=True) %} | ||
|
||
{{ dbt_utils.get_tables_by_pattern(schema_pattern, table_pattern, exclude, database) }} | ||
|
||
{%- endcall -%} | ||
|
||
{%- set table_list = load_result('get_tables') -%} | ||
|
||
{%- if table_list and table_list['table'] -%} | ||
{%- set tbl_relations = [] -%} | ||
{%- for row in table_list['table'] -%} | ||
{%- set tbl_relation = api.Relation.create(database, row.table_schema, row.table_name) -%} | ||
{%- do tbl_relations.append(tbl_relation) -%} | ||
{%- endfor -%} | ||
|
||
{{ return(tbl_relations) }} | ||
{%- else -%} | ||
{{ return([]) }} | ||
{%- endif -%} | ||
|
||
{% endmacro %} |
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,12 @@ | ||
{% macro get_tables_by_pattern(schema_pattern, table_pattern, exclude='', database=target.database) %} | ||
|
||
select distinct | ||
table_schema as "table_schema", table_name as "table_name" | ||
from {{database}}.information_schema.tables | ||
where table_schema ilike '{{ schema_pattern }}' | ||
and table_name ilike '{{ table_pattern }}' | ||
and table_name not ilike '{{ exclude }}' | ||
|
||
{% endmacro %} | ||
|
||
|