QuestionQ47

Verified

You have created a model named stg_tasks and now need to implement tests.

You provide the following in schema.yml:

version: 2  
models:  
  - name: stg_tasks  
    columns:  
      - name: completed_at  
        tests:  
          - not_null:  
              - config:  
                  where: "state = 'completed'"  

You receive this compilation error:

[WARNING]: Did not find matching node for patch with name 'stg_tasks' in the 'models' section of file 'models/example/schema.yml'  

How can you change the configuration of the not_null test to fix this compiler error?

Configuration A:

tests:  
  - not_null:  
      - config:  
          where: "state = 'completed'"  

Configuration B:

tests:  
  - not_null:  
      config:  
        where: "state = 'completed'"  

Configuration C:

tests:  
  - not_null:  
    config:  
      where: "state = 'completed'"  

Configuration D:

tests:  
  - not_null:  
  - config:  
      where: "state = 'completed'"  
Explanation

dbt reads every entry under tests as a mapping with one key: the test name, whose value is a mapping of the test's arguments and its config. Configuration B nests config, and where inside it, as a mapping under not_null, which is the documented way to configure a generic test.

Configuration A is the original definition: the extra dash makes the value of not_null a list, so dbt cannot read config as the test's configuration. Configuration C puts config beside not_null in the same entry, which gives the entry two keys instead of one. Configuration D turns config into a separate list item, which dbt would treat as a second test named config.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!