calogica / dbt-expectations

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

Add group_by option to expect_column_values_to_be_within_n_moving_stdevs #182

Closed clausherther closed 1 year ago

clausherther commented 2 years ago

Closes #166 This PR adds an option to specify a grouping level for the expect_column_values_to_be_within_n_moving_stdevs test. This allows uses to check for anomalies over time within groups, such as products or customers.

if group_by is specified, the macro groups the initial metric aggregation and then adds partition_by statements to the relevant window functions.

E.g.

  - name : my_model
    columns:
      - name: row_value
        tests:
          - dbt_expectations.expect_column_values_to_be_within_n_moving_stdevs:
              date_column_name: date_day
              group_by: [group_id]
              sigma_threshold: 3
              take_logs: true
              severity: warn
clausherther commented 2 years ago

@jordanjbanal lmk if this is what you had in mind with #166!