diff --git a/integration_tests/models/schema_tests/data_test.sql b/integration_tests/models/schema_tests/data_test.sql index cca11ac..db8bf23 100644 --- a/integration_tests/models/schema_tests/data_test.sql +++ b/integration_tests/models/schema_tests/data_test.sql @@ -1,8 +1,8 @@ select 1 as idx, '2020-10-21' as date_col, - cast(0 as {{ dbt.type_float() }}) as col_numeric_a, - cast(1 as {{ dbt.type_float() }}) as col_numeric_b, + cast(0 as {{ dbt.type_numeric() }}) as col_numeric_a, + cast(1 as {{ dbt.type_numeric() }}) as col_numeric_b, 'a' as col_string_a, 'b' as col_string_b, cast(null as {{ dbt.type_string() }}) as col_null, @@ -13,8 +13,8 @@ union all select 2 as idx, '2020-10-22' as date_col, - 1 as col_numeric_a, - 0 as col_numeric_b, + cast(1 as {{ dbt.type_numeric() }}) as col_numeric_a, + cast(0 as {{ dbt.type_numeric() }}) as col_numeric_b, 'b' as col_string_a, 'ab' as col_string_b, null as col_null, @@ -25,8 +25,8 @@ union all select 3 as idx, '2020-10-23' as date_col, - 0.5 as col_numeric_a, - 0.5 as col_numeric_b, + cast(0.5 as {{ dbt.type_numeric() }}) as col_numeric_a, + cast(0.5 as {{ dbt.type_numeric() }}) as col_numeric_b, 'c' as col_string_a, 'abc' as col_string_b, null as col_null, @@ -37,8 +37,8 @@ union all select 4 as idx, '2020-10-23' as date_col, - 0.5 as col_numeric_a, - 0.5 as col_numeric_b, + cast(0.5 as {{ dbt.type_numeric() }}) as col_numeric_a, + cast(0.5 as {{ dbt.type_numeric() }}) as col_numeric_b, 'c' as col_string_a, 'abcd' as col_string_b, null as col_null, diff --git a/integration_tests/models/schema_tests/schema.yml b/integration_tests/models/schema_tests/schema.yml index f9028f8..e8b6a41 100644 --- a/integration_tests/models/schema_tests/schema.yml +++ b/integration_tests/models/schema_tests/schema.yml @@ -505,6 +505,20 @@ models: value_set: [0.5] top_n: 1 quote_values: false + data_type: "{{ dbt.type_numeric() }}" + - dbt_expectations.expect_column_most_common_value_to_be_in_set: + value_set: [0.5, 0, 1] + top_n: 2 + quote_values: false + data_type: "{{ dbt.type_numeric() }}" + - dbt_expectations.expect_column_most_common_value_to_be_in_set: + value_set: [0.5, 0] + top_n: 2 + quote_values: false + data_type: "{{ dbt.type_numeric() }}" + config: + error_if: "=0" + warn_if: "<>1" - dbt_expectations.expect_column_values_to_be_increasing: sort_column: col_numeric_a strictly: false diff --git a/macros/schema_tests/aggregate_functions/expect_column_most_common_value_to_be_in_set.sql b/macros/schema_tests/aggregate_functions/expect_column_most_common_value_to_be_in_set.sql index 11ef689..f60e8fb 100644 --- a/macros/schema_tests/aggregate_functions/expect_column_most_common_value_to_be_in_set.sql +++ b/macros/schema_tests/aggregate_functions/expect_column_most_common_value_to_be_in_set.sql @@ -3,7 +3,7 @@ value_set, top_n, quote_values=True, - data_type="decimal", + data_type=None, row_condition=None ) -%} @@ -22,6 +22,8 @@ row_condition ) %} +{% set data_type = dbt.type_numeric() if not data_type else data_type %} + with value_counts as ( select @@ -48,7 +50,7 @@ value_counts_ranked as ( select *, - row_number() over(order by value_count desc) as value_count_rank + rank() over(order by value_count desc) as value_count_rank from value_counts @@ -60,7 +62,7 @@ value_count_top_n as ( from value_counts_ranked where - value_count_rank = {{ top_n }} + value_count_rank <= {{ top_n }} ), set_values as (