-
Notifications
You must be signed in to change notification settings - Fork 499
/
get_relations_by_prefix.sql
32 lines (24 loc) · 1.07 KB
/
get_relations_by_prefix.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_prefix(schema, prefix, exclude='', database=target.database) %}
{{ return(adapter.dispatch('get_relations_by_prefix', 'dbt_utils')(schema, prefix, exclude, database)) }}
{% endmacro %}
{% macro default__get_relations_by_prefix(schema, prefix, exclude='', database=target.database) %}
{%- call statement('get_tables', fetch_result=True) %}
{{ dbt_utils.get_tables_by_prefix_sql(schema, prefix, 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 %}