-
Notifications
You must be signed in to change notification settings - Fork 496
/
get_relations_by_pattern.sql
32 lines (24 loc) · 1.13 KB
/
get_relations_by_pattern.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{% macro get_relations_by_pattern(schema_pattern, table_pattern, exclude='', database=target.database) %}
{{ return(adapter.dispatch('get_relations_by_pattern', 'dbt_utils')(schema_pattern, table_pattern, exclude, database)) }}
{% endmacro %}
{% macro default__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_sql(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=database,
schema=row.table_schema,
identifier=row.table_name,
type=row.table_type
) -%}
{%- do tbl_relations.append(tbl_relation) -%}
{%- endfor -%}
{{ return(tbl_relations) }}
{%- else -%}
{{ return([]) }}
{%- endif -%}
{% endmacro %}