diff --git a/macros/utils/aggregations/_min_or_max.sql b/macros/utils/aggregations/_min_or_max.sql index 7041719..26ff817 100644 --- a/macros/utils/aggregations/_min_or_max.sql +++ b/macros/utils/aggregations/_min_or_max.sql @@ -1,4 +1,8 @@ {% macro _min_or_max(min_or_max, qualified_col) %} + {{ return(adapter.dispatch('_min_or_max','dbt_activity_schema')(min_or_max, qualified_col)) }} +{%- endmacro -%} + +{% macro default___min_or_max(min_or_max, qualified_col) -%} {% set aggregation = "min" if min_or_max == "min" else "max" %} {% set column_name = qualified_col.split(".")[-1].strip() %} @@ -54,3 +58,18 @@ {% do return(output) %} {% endmacro %} + +{% macro snowflake___min_or_max(min_or_max, qualified_col) -%} +{% set aggregation = "min_by" if min_or_max == "min" else "max_by" %} +{% set qualified_ts_col = "{}.{}".format( + dbt_activity_schema.appended(), dbt_activity_schema.columns().ts +) %} + +{# Apply min or max by to the selected column. #} +{% set aggregated_col %} + {{ aggregation }}({{ qualified_col }}, {{ qualified_ts_col }}) +{% endset %} + +{# Return output. #} +{% do return(aggregated_col) %} +{%- endmacro %}