Skip to content

Commit

Permalink
feat(bigquery): only add 'bytes_processed' column in case the adapter…
Browse files Browse the repository at this point in the history
… type is BigQuery. Remove as well unncessary helper logs
  • Loading branch information
charles-astrafy committed Aug 28, 2022
1 parent 66443f5 commit 15ef765
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 6 deletions.
2 changes: 0 additions & 2 deletions macros/create_model_executions_table_if_not_exists.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
query_completed_at TIMESTAMP,
total_node_runtime DOUBLE,
rows_affected INTEGER,
bytes_processed INTEGER,
materialization STRING,
schema STRING,
name STRING
Expand All @@ -48,7 +47,6 @@
query_completed_at TIMESTAMP_TZ,
total_node_runtime DOUBLE,
rows_affected INTEGER,
bytes_processed INTEGER,
materialization STRING,
schema STRING,
name STRING
Expand Down
1 change: 0 additions & 1 deletion macros/upload_model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@

{{ model.execution_time }}, {# total_node_runtime #}
null, -- rows_affected not available {# Only available in BigQuery #}
null, -- bytes_processed not available {# Only available in BigQuery #}
'{{ model.node.config.materialized }}', {# materialization #}
'{{ model.node.schema }}', {# schema #}
'{{ model.node.name }}' {# name #}
Expand Down
1 change: 0 additions & 1 deletion macros/upload_results.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
{% do log("Uploading seed executions", true) %}
{% set src_dbt_seed_executions = source('dbt_artifacts', 'seed_executions') %}
{% set content_seed_executions = dbt_artifacts.upload_seed_executions(results) %}
{% do log("FROUFROU " ~ content_seed_executions) %}
{{ dbt_artifacts.insert_into_metadata_table(
database_name=src_dbt_seed_executions.database,
schema_name=src_dbt_seed_executions.schema,
Expand Down
1 change: 1 addition & 0 deletions macros/upload_seed_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
'{{ model.node.schema }}', {# schema #}
'{{ model.node.name }}' {# name #}
)
{%- if not loop.last %},{%- endif %}
{%- endfor %}
{% endset %}
{{ seed_execution_values }}
Expand Down
1 change: 0 additions & 1 deletion macros/upload_seeds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% for node in graph.nodes.values() | selectattr("resource_type", "equalto", "seed") %}
{% do seeds.append(node) %}
{% endfor %}
{% do log("TUTU " ~ seeds) %}
{{ return(adapter.dispatch('get_seeds_dml_sql', 'dbt_artifacts')(seeds)) }}
{%- endmacro %}

Expand Down
10 changes: 10 additions & 0 deletions models/dim_dbt__current_models.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ latest_models_runs as (
, model_executions.query_completed_at
, model_executions.total_node_runtime
, model_executions.rows_affected
{% if target.type == 'bigquery' %}
, model_executions.bytes_processed
{% endif %}
, row_number() over (
partition by latest_models.node_id, model_executions.was_full_refresh
order by model_executions.query_completed_at desc /* most recent ranked first */
Expand All @@ -40,11 +42,15 @@ latest_model_stats as (
, max(case when was_full_refresh then query_completed_at end) as last_full_refresh_run_completed_at
, max(case when was_full_refresh then total_node_runtime end) as last_full_refresh_run_total_runtime
, max(case when was_full_refresh then rows_affected end) as last_full_refresh_run_rows_affected
{% if target.type == 'bigquery' %}
, max(case when was_full_refresh then bytes_processed end) as last_full_refresh_run_bytes_processed
{% endif %}
, max(query_completed_at) as last_run_completed_at
, max(total_node_runtime) as last_run_total_runtime
, max(rows_affected) as last_run_rows_affected
{% if target.type == 'bigquery' %}
, max(bytes_processed) as last_run_bytes_processed
{% endif %}
from latest_models_runs
where run_idx = 1
group by 1
Expand All @@ -56,11 +62,15 @@ final as (
, latest_model_stats.last_full_refresh_run_completed_at
, latest_model_stats.last_full_refresh_run_total_runtime
, latest_model_stats.last_full_refresh_run_rows_affected
{% if target.type == 'bigquery' %}
, latest_model_stats.last_full_refresh_run_bytes_processed
{% endif %}
, latest_model_stats.last_run_completed_at
, latest_model_stats.last_run_total_runtime
, latest_model_stats.last_run_rows_affected
{% if target.type == 'bigquery' %}
, latest_model_stats.last_run_bytes_processed
{% endif %}
from latest_models
left join latest_model_stats
on latest_models.node_id = latest_model_stats.node_id
Expand Down
2 changes: 2 additions & 0 deletions models/fct_dbt__model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ model_executions as (
query_completed_at,
total_node_runtime,
rows_affected,
{% if target.type == 'bigquery' %}
bytes_processed,
{% endif %}
materialization,
schema,
name
Expand Down
4 changes: 3 additions & 1 deletion models/staging/stg_dbt__model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ enhanced as (
query_completed_at,
total_node_runtime,
rows_affected,
bytes_processed,
{% if target.type == 'bigquery' %}
bytes_processed,
{% endif %}
materialization,
schema,
name
Expand Down

0 comments on commit 15ef765

Please sign in to comment.