Chris Dong
03/02/2024, 11:02 PMdispatch:
- macro_namespace: elementary # overriding macros in elementary package
search_order: ["<project_name>", "elementary"]
Attempt 1
{% macro query_table_metrics() -%}
{{ return(adapter.dispatch('query_table_metrics', 'elementary')()) }}
{% endmacro %}
{% macro default__query_table_metrics() %}
<MY LOGIC GOES HERE>
{# select
{{ modules.datetime.datetime.utcnow().timestamp() }} as build_timestamp,
count(*) as row_count
from {{ this }}
#}
{% endset %}
{% set metrics = [] %}
{% for metric_column in elementary.run_query(query).columns %}
{% set metric_name = metric_column.name %}
{% set metric_value = metric_column[0] %}
{% do metrics.append({
"id": "{}.{}".format(invocation_id, this),
"full_table_name": elementary.relation_to_full_name(this),
"column_name": none,
"metric_name": metric_name,
"metric_value": metric_value,
"updated_at": elementary.datetime_now_utc_as_string()
}) %}
{% endfor %}
{% do return(metrics) %}
{% endmacro %}
Attempt 2
{% macro query_table_metrics() %}
<MY LOGIC GOES HERE>
{# select
{{ modules.datetime.datetime.utcnow().timestamp() }} as build_timestamp,
count(*) as row_count
from {{ this }}
#}
{% endset %}
{% set metrics = [] %}
{% for metric_column in elementary.run_query(query).columns %}
{% set metric_name = metric_column.name %}
{% set metric_value = metric_column[0] %}
{% do metrics.append({
"id": "{}.{}".format(invocation_id, this),
"full_table_name": elementary.relation_to_full_name(this),
"column_name": none,
"metric_name": metric_name,
"metric_value": metric_value,
"updated_at": elementary.datetime_now_utc_as_string()
}) %}
{% endfor %}
{% do return(metrics) %}
{% endmacro %}
Attempt 3:
{% macro query_table_metrics() %}
<MY LOGIC GOES HERE>
{# select
{{ modules.datetime.datetime.utcnow().timestamp() }} as build_timestamp,
count(*) as row_count
from {{ this }}
#}
{% endset %}
{% set metrics = [] %}
{% for metric_column in elementary.run_query(query).columns %}
{% set metric_name = metric_column.name %}
{% set metric_value = metric_column[0] %}
{% do metrics.append({
"id": "{}.{}".format(invocation_id, this),
"full_table_name": elementary.relation_to_full_name(this),
"column_name": none,
"metric_name": metric_name,
"metric_value": metric_value,
"updated_at": elementary.datetime_now_utc_as_string()
}) %}
{% endfor %}
{% do return(metrics) %}
{% endmacro %}
{% macro query_metrics() %}
{% if not elementary.can_query_metrics() %}
{% do return([]) %}
{% endif %}
{% do return(query_table_metrics()) %} {# use override instead #}
{# {% do return(elementary.query_table_metrics()) %} #}
{% endmacro %}Idan Shavit
03/03/2024, 9:55 AMChris Dong
03/03/2024, 10:27 PMChris Dong
03/03/2024, 10:28 PMIdan Shavit
03/04/2024, 8:12 AMquery_table_metrics() - In that case dbt goes over all of the installed packages and uses the first one it matches
2. By using both the name of the macro and the name of the package it is defined at for example elementary.query_table_metric() - In that case dbt goes directly to the specified package and uses the macro that is defined there.
At Elementary we use the second option. The reason for that is it prevents users overriding Elementary's macros by mistake (if they where using the same macro name as we), and more importantly it prevents from Elementary to override users' macros.
The reason you were able to override dbt_utils macros is because they probably were using the 1 option in their package.Idan Shavit
03/04/2024, 8:13 AMquery_table_metrics - if it is important, we can try and find a solution for that specific macro for you 🙂Chris Dong
03/04/2024, 5:54 PMChris Dong
03/04/2024, 5:55 PMif it is important, we can try and find a solution for that specific macro for youhappy to make a open source contribution for bigquery specifically if this is the only way to get this change in. though slight preference to be able to override in our own deployment (otherwise we'll need to upgrade the version) but totally understand if it doesnt seem possible
Idan Shavit
03/05/2024, 11:33 AMChris Dong
03/05/2024, 5:37 PMIdan Shavit
03/06/2024, 6:48 AMChris Dong
03/08/2024, 1:43 AMChris Dong
03/08/2024, 1:48 AMdbt/dbt_packages/elementary/macros/edr/materializations/model/metrics.sqlItamar Hartstein
03/08/2024, 5:06 PMItamar Hartstein
03/08/2024, 5:09 PM- git: <https://github.com/elementary-data/dbt-data-reliability.git>
revision: 1962263ad78bad990b7de20c3e1cb2e0742a45b9
but anyway will review as soon as possibleChris Dong
03/11/2024, 4:17 PMItamar Hartstein
03/11/2024, 4:20 PMItamar Hartstein
03/11/2024, 4:23 PMChris Dong
03/11/2024, 4:27 PM# - package: elementary-data/elementary
# version: 0.13.2
# <https://github.com/elementary-data/dbt-data-reliability/pull/674>
- git: <https://github.com/elementary-data/dbt-data-reliability.git>
revision: 5e5ad3555c69982684abc89a457e8c2ae86f4042
so this is what i have in my packages.yml
but in production, i dont see the query being ran to get the row count anymoreChris Dong
03/28/2024, 6:19 PMChris Dong
04/01/2024, 10:54 PMItamar Hartstein
04/03/2024, 11:37 AMChris Dong
04/18/2024, 5:55 AM