Skip to content

Commit

Permalink
add redshift__measure_avg (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenconnorg authored Sep 26, 2023
1 parent 400c548 commit c1c7850
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions macros/measures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ case when count(distinct {{ adapter.quote(column_name) }}) = count(*) then 1 els
{%- endmacro -%}


{%- macro redshift__measure_avg(column_name, data_type) -%}

{%- if dbt_profiler.is_numeric_dtype(data_type) and not dbt_profiler.is_struct_dtype(data_type) -%}
avg({{ adapter.quote(column_name) }}::float)
{%- elif dbt_profiler.is_logical_dtype(data_type) -%}
avg(case when {{ adapter.quote(column_name) }} then 1.0 else 0.0 end)
{%- else -%}
cast(null as {{ dbt.type_numeric() }})
{%- endif -%}

{%- endmacro -%}

{# measure_median ------------------------------------------------- #}

{%- macro measure_median(column_name, data_type) -%}
Expand Down

0 comments on commit c1c7850

Please sign in to comment.