dbt-labs / dbt-audit-helper

Useful macros when performing data audits

Home Page:https://hub.getdbt.com/dbt-labs/audit_helper/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README.md is ineffective for dbt cloud

jerichomcleod opened this issue · comments

Describe the bug

The section compare_column_values -> Advanced usage - dbt Cloud contains a code snippet for replacing the .print_table() function, but the code snippet does not work in dbt cloud.

Steps to reproduce

Use the code snippet

{# in dbt Develop #}

{% set old_etl_relation_query %}
    select * from public.dim_product
    where is_latest
{% endset %}

{% set new_etl_relation_query %}
    select * from {{ ref('dim_product') }}
{% endset %}

{% set audit_query = audit_helper.compare_column_values(
    a_query=old_etl_relation_query,
    b_query=new_etl_relation_query,
    primary_key="product_id",
    column_to_compare="status"
) %}

{% set audit_results = run_query(audit_query) %}

{% do log(audit_results.column_names, info=True) %}
{% for row in audit_results.rows %}
    {% do log(row.values(), info=True) %}
{% endfor %}

As suggested by the readme, where the last 4 lines include the suggested code change to make this compatible with dbt cloud.

The actual expected results can be obtained by instead directly invoking the macro:

{# in dbt Develop #}

{% set old_etl_relation_query %}
    select * from public.dim_product
    where is_latest
{% endset %}

{% set new_etl_relation_query %}
    select * from {{ ref('dim_product') }}
{% endset %}

{{ audit_helper.compare_column_values(
    a_query=old_etl_relation_query,
    b_query=new_etl_relation_query,
    primary_key="product_id",
    column_to_compare="status"
) }}

@jerichomcleod thanks for this callout - I'd welcome a PR to the readme to improve this!

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.