I am using the doc macro in my YML file.
I need to use the column definition (retrieve the doc() result) into a custom macro, but the doc is undefined.
The context of why I’m trying to do this
I would like to generate the SQL file from the YML file.
Because I do not want to copy/paste the description of my columns between the different layers, I am using the doc() macro.
{% macro generate_view(sv) %}
..
{%- set facts = [] %}
{%- for table in sv.tables %}
{%- for col in table.columns if col.type == 'fact' %}
{%- do facts.append({'table': table.name, 'col': col}) %}
{%- endfor %}
{%- endfor %}
{%- for item in facts %}
{{ item.table }}.{{ item.col.name }} as {{ item.col.expr }} WITH SYNONYMS = ({% for syn in item.col.synonyms %}'{{ syn }}'{{ ", " if not loop.last }}{% endfor %}) COMMENT = '{{ item.col.description }}'{{ "," if not loop.last }}
{%- endfor %}
..
{% endmacro %}
this part of the code is the issue :
COMMENT = '{{ item.col.description }}'
How I run it :
dbt run-operation generate_semantic_view
this is the output
Compilation Error Could not render {{ doc(“business_key”) }}: ‘doc’ is undefined
This Execute is only here to tell us if we are in parsing mode or run mode, right?
This won’t “execute” anything. right? Yes exactly.
I’m not saying that docs are not working when calling a posthook, im saying im unfamiliar with when the docs are passed to the COMMENTs and how (because what you are trying to achieve is basically a persist docs thing), im just wondering when the queries are generated, I feel like they are passed for the specific model directly, it’s probably not like it gets replaced in the YML and then generated (if you see what I’m trying to say).