dbt debug macro 简单说明

dbt 支持debug macro 可以用来进行调试

使用

{% macro my_macro() %}
 
  {% set something_complex = my_complicated_macro() %}
 
  {{ debug() }}
 
{% endmacro %}

参考实现

实际上就是通过环境变量开启了一个debug 上下文变量

if os.environ.get("DBT_MACRO_DEBUGGING"):
 
    @contextmember()
    @staticmethod
    def debug():
        """Enter a debugger at this line in the compiled jinja code."""
        import sys
        import ipdb  # type: ignore
 
        frame = sys._getframe(3)
        ipdb.set_trace(frame)
        return ""

参考资料

https://docs.getdbt.com/reference/dbt-jinja-functions/debug-method
https://github.com/gotcha/ipdb

posted on 2024-04-05 08:00  荣锋亮  阅读(10)  评论(0编辑  收藏  举报

导航