calogica / dbt-expectations

Port(ish) of Great Expectations to dbt test macros
https://calogica.github.io/dbt-expectations/
Apache License 2.0
989 stars 120 forks source link

expect_column_proportion_of_unique_values_to_be_between throwing a compilation error #306

Closed manuel-niederl closed 2 months ago

manuel-niederl commented 2 months ago

Hello! Not sure if this issue is widespread or just due to my installation but the change made to this test in 10.3 is breaking our existing implementation of the test. I'm running dbt 1.2.6.

This line was changed from

count(distinct {{ column_name }})*1.0/count({{ column_name }})

to

cast(count(distinct {{ column_name }}) as {{ dbt.type_float() }})/count({{ column_name }})

which is throwing this error on our end:

dbt.exceptions.CompilationException: Compilation Error in test dbt_expectations_expect_column_proportion_of_unique_values_to_be_between_dim_invite_experiments_guest_id__1__0_99__guest_id_is_not_null (models/invite/core/invite-experimentation/_invite_experimentation.yml)
  'dict object' has no attribute 'type_float'

Please advise if this is a bug or an issue with my installation.

Update: Updating to DBT 1.3.7 fixed this issue but I still believe that I should not have encountered the bug because expectations supports lower DBT versions.

clausherther commented 2 months ago

I don't remember which version of dbt brought the jinja type macros into the dbt namespace but I assume the version of dbt you're using is too old. The current stable release is 1.7.x.

https://docs.getdbt.com/reference/dbt-jinja-functions/cross-database-macros#type_float

We only test and therefore only really support the latest stable release minor version, so currently 1.7.x.

clausherther commented 2 months ago

FYI, I updated the README to reflect the supported version.

manuel-niederl commented 2 months ago

Thanks a lot for the quick answer and for updating the Readme!