Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ Call this macro from another macro or dbt model:

## print_profile ([source](macros/print_profile.sql))

❗ **This macro does not work in dbt Cloud. The profile doesn't display in the cloud console log because the underlying [print_table()](https://agate.readthedocs.io/en/1.6.1/api/table.html#agate.Table.print_table) method is disabled.**

This macro prints a relation profile as a Markdown table to `stdout`.

### Arguments
Expand Down Expand Up @@ -337,8 +335,6 @@ This what the profile looks like on the dbt docs site:

## print_profile_docs ([source](macros/print_profile_docs.sql))

❗ **This macro does not work in dbt Cloud. The profile doesn't display in the cloud console log because the underlying [print_table()](https://agate.readthedocs.io/en/1.6.1/api/table.html#agate.Table.print_table) method is disabled.**

This macro prints a relation profile as a Markdown table wrapped in a Jinja `docs` macro to `stdout`.

### Arguments
Expand Down
2 changes: 1 addition & 1 deletion macros/print_profile.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{%- 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 execute %}
{% do results.print_table(max_rows=max_rows, max_columns=max_columns, max_column_width=max_column_width, max_precision=max_precision) %}
{{ dbt_profiler.print_table(results, max_rows=max_rows, max_columns=max_columns, max_column_width=max_column_width, max_precision=max_precision) }}
{% endif %}

{% endmacro %}
50 changes: 3 additions & 47 deletions macros/print_profile_docs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,10 @@
{%- 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 -%}
{{ print(startdocs) }}
{{ dbt_profiler.print_table(results, max_rows=max_rows, max_columns=max_columns, max_column_width=max_column_width, max_precision=max_precision) }}
{{ print(enddocs) }}

{% 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 %}

Expand Down
31 changes: 31 additions & 0 deletions macros/print_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% macro print_table(table, max_rows=none, max_columns=13, max_column_width=30, max_precision=none) %}

{# Check if macro is called in dbt Cloud #}
{%- set is_dbt_cloud = flags.WHICH == 'rpc' -%}

{%- if not is_dbt_cloud -%}
{% do results.print_table(max_rows=max_rows, max_columns=max_columns, max_column_width=max_column_width, max_precision=max_precision) %}
{% else %}
{%- set table_printout_lines = [] -%}

{# Get header from column names #}
{%- set headers = results.column_names | list -%}
{%- set horizontal_lines = ['---'] * headers | length -%}
{% do table_printout_lines.append('| ' ~ headers | join(' | ') ~ ' |') %}
{% do table_printout_lines.append('| ' ~ horizontal_lines | join(' | ') ~ ' |') %}

{# Get row values #}
{% for row in results.rows %}
{%- set list_row = [''] -%}
{% for val in row.values() %}
{% do list_row.append(val) %}
{% endfor %}
{% do table_printout_lines.append(list_row | join(' | ') ~ ' |') %}
{% endfor %}

{%- set table_printout = table_printout_lines | join ('\n') -%}
{{ print(table_printout) }}
{% endif %}


{% endmacro %}