DBT模型编译报错:嵌套标签无匹配{% endmacro %}问题求助
DBT模型编译错误排查与解决
问题重现
尝试运行以下DBT模型:
{{ config( materialized="table", table_type="iceberg", format="parquet", partitioned_by=["bucket(a_id, 50)"], table_properties={"optimize_rewrite_delete_file_threshold": "2"}, ) }} select * from {{ source("source", "table1") }} as a left join {{ source("source", "table2") }} as ao on a.a_id = ao.ao_a_id and a.db_name = ao.db_name left join {{ source("source", "table3") }} as aof on ao.ao_id = aof.aof_id and ao.db_name = aof.db_name
出现编译错误:
Compilation Error Got nested tags: macro (started at 498) did not have a matching {{% endmacro %}} before a subsequent macro was found (started at 548)
解决步骤
- 检查当前模型文件:仔细查看文件内容,确认是否混入了未闭合的
{% macro ... %}标签(包括注释行里的残留代码),补充对应的{% endmacro %}。 - 排查全局宏文件:检查项目
macros/目录下的所有宏文件,确认是否存在未完成的宏定义(缺少{% endmacro %})。 - 清除格式干扰:将模型代码复制到纯文本编辑器,检查是否有不可见的特殊字符,重新保存为无格式问题的文件。
- 逐步简化定位:先保留
config和最简单的select * from {{ source("source", "table1") }},验证编译是否正常。若正常,再逐个添加join语句,定位触发错误的代码段。 - 验证分区语法:部分Iceberg适配器要求分区函数使用模板语法而非字符串,尝试调整
partitioned_by写法(以适配所用dbt适配器为准):partitioned_by=[{{ bucket(a_id, 50) }}],
内容的提问来源于stack exchange,提问作者darkCoffy
相关产品推荐
相关产品推荐

