-
Notifications
You must be signed in to change notification settings - Fork 15
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 #10 from fishtown-analytics/feature/get-relations-by
Some dbt_utils.get_relations_by_* macros
- Loading branch information
Showing
5 changed files
with
45 additions
and
8 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
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
Submodule dbt-utils
updated
from 86cb6e to ceb284
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
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,41 @@ | ||
{% macro spark__get_relations_by_pattern(schema_pattern, table_pattern, exclude='', database=target.database) %} | ||
|
||
{%- call statement('get_tables', fetch_result=True) %} | ||
|
||
show table extended in {{ schema_pattern }} like '{{ table_pattern }}' | ||
|
||
{%- 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=None, | ||
schema=row[0], | ||
identifier=row[1], | ||
type=('view' if 'Type: VIEW' in row[3] else 'table') | ||
) -%} | ||
{%- do tbl_relations.append(tbl_relation) -%} | ||
{%- endfor -%} | ||
|
||
{{ return(tbl_relations) }} | ||
{%- else -%} | ||
{{ return([]) }} | ||
{%- endif -%} | ||
|
||
{% endmacro %} | ||
|
||
{% macro spark__get_relations_by_prefix(schema_pattern, table_pattern, exclude='', database=target.database) %} | ||
{% set table_pattern = table_pattern ~ '*' %} | ||
{{ return(spark_utils.spark__get_relations_by_pattern(schema_pattern, table_pattern, exclude='', database=target.database)) }} | ||
{% endmacro %} | ||
|
||
{% macro spark__get_tables_by_pattern(schema_pattern, table_pattern, exclude='', database=target.database) %} | ||
{{ return(spark_utils.spark__get_relations_by_pattern(schema_pattern, table_pattern, exclude='', database=target.database)) }} | ||
{% endmacro %} | ||
|
||
{% macro spark__get_tables_by_prefix(schema_pattern, table_pattern, exclude='', database=target.database) %} | ||
{{ return(spark_utils.spark__get_relations_by_prefix(schema_pattern, table_pattern, exclude='', database=target.database)) }} | ||
{% endmacro %} |