Skip to content

Commit

Permalink
Add upload_model_executions support
Browse files Browse the repository at this point in the history
  • Loading branch information
HingeAntoine committed Oct 8, 2024
1 parent b38b91f commit 0a53283
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions macros/upload_individual_datasets/upload_model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,48 @@
{% endif %}
{% endmacro -%}

{% macro athena__get_model_executions_dml_sql(models) -%}
{% if models != [] %}
{% set model_execution_values %}
values
{% for model in models -%}
(
'{{ invocation_id }}', {# command_invocation_id #}
'{{ model.node.unique_id }}', {# node_id #}
CAST('{{ run_started_at }}' AS timestamp), {# run_started_at #}

{% set config_full_refresh = model.node.config.full_refresh %}
{% if config_full_refresh is none %}
{% set config_full_refresh = flags.FULL_REFRESH %}
{% endif %}
{{ config_full_refresh }}, {# was_full_refresh #}

'{{ model.thread_id }}', {# thread_id #}
'{{ model.status }}', {# status #}

{% set compile_started_at = (model.timing | selectattr("name", "eq", "compile") | first | default({}))["started_at"] %}
{% if compile_started_at %}CAST('{{ compile_started_at }}' AS timestamp){% else %}null{% endif %}, {# compile_started_at #}
{% set query_completed_at = (model.timing | selectattr("name", "eq", "execute") | first | default({}))["completed_at"] %}
{% if query_completed_at %}CAST('{{ query_completed_at }}' AS timestamp){% else %}null{% endif %}, {# query_completed_at #}

{{ model.execution_time }}, {# total_node_runtime #}
safe_cast('{{ model.adapter_response.rows_affected }}' as int64),
safe_cast('{{ model.adapter_response.bytes_processed }}' as int64),
'{{ model.node.config.materialized }}', {# materialization #}
'{{ model.node.schema }}', {# schema #}
'{{ model.node.name }}', {# name #}
'{{ model.node.alias }}', {# alias #}
'{{ model.message | replace("\\", "\\\\") | replace("'", "''") | replace("\n", "\\n") }}', {# message #}
'{{ adapter.dispatch('parse_json', 'dbt_artifacts')(tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "''")) }}' {# adapter_response #}
)
{%- if not loop.last %},{%- endif %}
{%- endfor %}
{% endset %}
{{ model_execution_values }}
{% else %} {{ return("") }}
{% endif %}
{%- endmacro %}

{% macro bigquery__get_model_executions_dml_sql(models) -%}
{% if models != [] %}
{% set model_execution_values %}
Expand Down

0 comments on commit 0a53283

Please sign in to comment.