-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make print_profile_docs work in dbt cloud (#77)
* Make print_profile_docs work in dbt cloud * Make print_profile_docs work in dbtCloud --------- Co-authored-by: nana_tran <[email protected]>
- Loading branch information
1 parent
b2cc1ad
commit a8b9c8f
Showing
1 changed file
with
59 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,65 @@ | ||
{% macro print_profile_docs(relation=none, relation_name=none, docs_name=none, schema=none, database=none, exclude_measures=[], include_columns=[], exclude_columns=[], max_rows=none, max_columns=13, max_column_width=30, max_precision=none, where_clause=none) %} | ||
|
||
{%- set results = dbt_profiler.get_profile_table(relation=relation, relation_name=relation_name, schema=schema, database=database, exclude_measures=exclude_measures, include_columns=include_columns, exclude_columns=exclude_columns, where_clause=where_clause) -%} | ||
|
||
{% if docs_name is none %} | ||
{% set docs_name = 'dbt_profiler__' + relation_name %} | ||
{% endif %} | ||
|
||
{% if execute %} | ||
{{ print('{% docs ' + docs_name + ' %}') }} | ||
{% do results.print_table(max_rows=max_rows, max_columns=max_columns, max_column_width=max_column_width, max_precision=max_precision) %} | ||
{{ print('{% enddocs %}') }} | ||
|
||
{%- set results = dbt_profiler.get_profile_table(relation=relation, relation_name=relation_name, schema=schema, database=database, exclude_measures=exclude_measures, include_columns=include_columns, exclude_columns=exclude_columns, where_clause=where_clause) -%} | ||
|
||
{% if docs_name is none %} | ||
{% set docs_name = 'dbt_profiler__' + relation_name %} | ||
{% endif %} | ||
|
||
{%- set startdocs = '{% docs ' ~ docs_name ~ ' %}' -%} | ||
{%- set enddocs = '{% enddocs %}' -%} | ||
|
||
{# Check if macro is called in dbt Cloud? #} | ||
{%- if flags.WHICH == 'rpc' -%} | ||
{%- set is_dbt_cloud = true -%} | ||
{%- else -%} | ||
{%- set is_dbt_cloud = false -%} | ||
{%- endif -%} | ||
|
||
{% if not is_dbt_cloud %} | ||
|
||
{{ print(startdocs) }} | ||
{% do results.print_table(max_rows=max_rows, max_columns=max_columns, max_column_width=max_column_width, max_precision=max_precision) %} | ||
{{ print(enddocs) }} | ||
|
||
{% else %} | ||
|
||
{%- set profile_docs=[] -%} | ||
{% do profile_docs.append(startdocs) -%} | ||
{% do profile_docs.append('') %} | ||
|
||
{# Get header from column names #} | ||
{%- set headers = results.column_names -%} | ||
{%- set header = [] -%} | ||
{%- set horizontal_line = [] -%} | ||
|
||
{% for i in range(0,headers|length) %} | ||
{% do header.append(headers[i]) %} | ||
{% do horizontal_line.append('---') %} | ||
{% endfor %} | ||
{% do profile_docs.append('| ' ~ header|join(' | ') ~ ' |') %} | ||
{% do profile_docs.append('| ' ~ horizontal_line|join(' | ') ~ ' |') %} | ||
|
||
{# Get row values #} | ||
{% for row in results.rows %} | ||
{%- set list_row = [''] -%} | ||
{% for val in row.values() %} | ||
{% do list_row.append(val) %} | ||
{% endfor %} | ||
{% do profile_docs.append(list_row|join(' | ') ~ ' |') %} | ||
{% endfor %} | ||
{% do profile_docs.append('') %} | ||
{% do profile_docs.append(enddocs) %} | ||
|
||
{# Join profile docs #} | ||
{%- set joined = profile_docs | join ('\n') -%} | ||
{{ log(joined, info=True) }} | ||
{% do return(joined) %} | ||
|
||
{% endif %} | ||
|
||
{% endif %} | ||
|
||
{% endmacro %} |