YAML anchors don't work with lists

Hi all,
I tried to set up anchoring while declaring tests as recommended here: Tests | dbt Docs

But i can’t figure out how it should work. I have this example:

 columns: &columns
   - '"date"'
   - name: ga_data
       - not_null:
           column_name: *columns

But what i get is an error message:

 001003 (42000): SQL compilation error:
 syntax error line 3 at position 6 unexpected '['.

This is the SQL that is put into target/schema_test:

select count(*)
where ['"date"'] is null

Can you help me out?
Ultimately, I want to have an easy way of testing ALL columns in a model for not_null without have to retype everything for each column.

1 Like

Hi @germanguy :wave:

Anchors can only be used for dictionaries, whereas here you’re using it for a list — check out this related issue on the Jinja library.

Hi claire, thanks for your help.
Did you post the correct link? This leads to an issues regarding “merge arrays” in the yaml github repo, which actually shows lists instead of dictionaries.
I found a link that explains it, https://docs.ansible.com/ansible/latest/user_guide/playbooks_advanced_syntax.html

Yep! The linked issue is a request for the functionality you’re trying to use, and the response basically being like “nah this won’t happen”

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.