forked from dbt-labs/dbt-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_relations_by_prefix.sql
More file actions
27 lines (19 loc) · 1013 Bytes
/
get_relations_by_prefix.sql
File metadata and controls
27 lines (19 loc) · 1013 Bytes
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
{% macro get_relations_by_prefix(schema, prefix, exclude='', database=target.database) %}
{{ adapter.dispatch('get_relations_by_prefix', packages = dbt_utils._get_utils_namespaces())(schema, prefix, exclude='', database=target.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, row.table_schema, row.table_name) -%}
{%- do tbl_relations.append(tbl_relation) -%}
{%- endfor -%}
{{ return(tbl_relations) }}
{%- else -%}
{{ return([]) }}
{%- endif -%}
{% endmacro %}