How to count the rows you've transformed

#1

After some pain, here we go! How to log out the number of lines transfomed into your model.

{% macro log_order_items() %}

{%- call statement('count_order_items', fetch_result=True) -%}
    SELECT count(*) as count from {{ this }}
{%- endcall -%}

{%- set total_order_items = load_result('count_order_items') -%}

{% if execute %}
    {{ log(modules.datetime.datetime.now().strftime('%H:%M:%S') ~ ' | Number of rows transformed ' ~ total_order_items['data'][0][0] ~ ' rows into a table', True) }}
{% endif %}

select 1

{% endmacro %}
#2
{% macro log_model() %}

{%- call statement('count', fetch_result=True) -%}
    SELECT count(*) as count from {{ this }}
{%- endcall -%}

{%- set model_count = load_result('count') -%}

{% if execute %}
    {{ log(modules.datetime.datetime.now().strftime('%H:%M:%S') ~ ' |         ' ~
        model_count['data'][0][0] ~ ' rows transformed into ' ~ this, True) }}
{% endif %}

select 1

{% endmacro %}