dbt-labs/dbt-utils

`dbt_utils.not_null_proportion` does not work with clickhouse

Opened this issue · 0 comments

Describe the bug

dbt_utils.not_null_proportion is returning 0 in clickhouse because it is not using floats for the division

Steps to reproduce

select
    sum(case when baz is null then 0 else 1 end) / cast(count(*) as numeric) as not_null_proportion
from `foo`.`bar`

which is basically

select 100/cast(200 as numeric)

returns 0 in clickhouse

Expected results

.5

Actual results

0

Which database are you using dbt with?

  • postgres
  • redshift
  • bigquery
  • snowflake
  • other (specify: clickhouse)

The output of dbt --version:

Core:
  - installed: 1.8.6
  - latest:    1.8.6 - Up to date!

Plugins:
  - clickhouse: 1.8.3

I think that the fix could just be to sum by 1.0 and 0.0 instead of 1 and 0 which should be the same across database, and just tells dbs to use float math correctly.

select 100.0/cast(200 as numeric)

works as expected