dbt render macro 简单说明

dbt render macro 官方文档并没有说明,但是在一些三方adapter 中发现有使用到简单说明下

参考使用

{% materialization external, adapter="duckdb", supported_languages=['sql', 'python'] %}
  {%- set location = render(config.get('location', default=external_location(this, config))) -%})
  {%- set rendered_options = render_write_options(config) -%}
.....

内部处理

  • context 定义
@contextmember
def render(self, string: str) -> str:
    return get_rendered(string, self._ctx, self.model)
  • get_rendered 处理

可以看到内部实际上是一个jinja2 的处理

def get_rendered(
    string: str,
    ctx: Dict[str, Any],
    node=None,
    capture_macros: bool = False,
    native: bool = False,
) -> str:
    # performance optimization: if there are no jinja control characters in the
    # string, we can just return the input. Fall back to jinja if the type is
    # not a string or if native rendering is enabled (so '1' -> 1, etc...)
    # If this is desirable in the native env as well, we could handle the
    # native=True case by passing the input string to ast.literal_eval, like
    # the native renderer does.
    if not native and isinstance(string, str) and _HAS_RENDER_CHARS_PAT.search(string) is None:
        return string
    template = get_template(
        string,
        ctx,
        node,
        capture_macros=capture_macros,
        native=native,
    )
    return render_template(template, ctx, node)

说明

render macro 官方没有说明,但是从功能上看似乎是一个很强大的macro,可以实现macro 再调用处理,如下

{% set  location = "{{this}}" %}
{{log("render    info " ~ render(location),info=True) }}
select * from {{myref('pg','sensor')}}

参考资料

https://github.com/duckdb/dbt-duckdb

posted on   荣锋亮  阅读(12)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-05-14 citus 11.3 新特性
2023-05-14 golang vrrp 包
2022-05-14 whichjdk 帮助选择合适的jdk 版本
2022-05-14 使用api-extractor 开发typescript 项目
2021-05-14 cube.js 严模式校验cube.js 文件
2021-05-14 cube.js预聚合对于大数据量处理的问题
2020-05-14 CDS是一个企业级的持续交付和DevOps自动化开源平台

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示