DBT age validation using conditional statement

416 views Asked by At

Hello I would like to ask for your assistance I'm planning to validate my age field on database however I'm not sure how to make it work on DBT. Your response is highly appreciated. Thank you

  - name: age
    tests:
      - not_null
  #     - dbt_expectations.expect_column_values_to_match_regex:
  #         regex: "[1-9]\\d{3,}"
  #     - dbt_utils.not_empty_string
  #     - dbt_utils.not_constant
      - dbt_utils.expression_is_true:
        expression: "age"
        config:
              where: "age > '110'"

enter image description here

I tried to use this syntax below however its not working and the complied statement showed.

  - name: age
    tests:
      - not_null
  #     - dbt_expectations.expect_column_values_to_match_regex:
  #         regex: "[1-9]\\d{3,}"
  #     - dbt_utils.not_empty_string
  #     - dbt_utils.not_constant
      - dbt_utils.expression_is_true:
          expression: '>= 110'

Result:

enter image description here

1

There are 1 answers

1
Josh D. On BEST ANSWER

You're really close! In dbt tests, you write what you want to pass the test and (for this test) then it puts not(<expression>) to find the rows that fail the test.

Because of that, this should do it:

  - name: age
    tests:
      - dbt_utils.expression_is_true:
          expression: '< 110'