gpt4 book ai didi

dbt pre-hooks 无法呈现/查找宏?

转载 作者:行者123 更新时间:2023-12-05 06:12:33 27 4
gpt4 key购买 nike

dbt_project.yml 模型预 Hook 无法呈现宏。以下实现:

# gold/dbt_project.yml

config-version: 2

...

models:
gold:
+pre-hooks: "{{ incremental_failsafe() }}"

和下面的宏:

-- gold/macros/utils/incremental_failsafe.sql

{% macro incremental_failsafe() %}

{# /*
Used to wrap AND clauses that should only be run on dev/CI dbt runs.

For example, to limit the number of records scanned on an incremental
table. This macro will return True unless the target profile is 'prod':

`dbt run --target prod`
*/ #}

{% if target.name == "prod" %}
{% set incremental_failsafe = False %}
{% else %}
{% set incremental_failsafe = True %}
{% endif %}

{{ log("Running with incremental_failsafe: " ~ incremental_failsafe, info=True) }}
{{ return(incremental_failsafe) }}

{% endmacro %}

结果如下:

(snowflake) Teghans-MacBook-Pro:gold tnightengale$ dbt compile
Running with dbt=0.17.2
Encountered an error:
Compilation Error
Could not render {{ incremental_failsafe() }}: 'incremental_failsafe' is undefined

我知道 dbt 0.17.0 围绕预 Hook 存在问题,如 this slack exchange 中所述.尽管我正在运行0.17.2(不是 0.17.0)。欢迎任何见解!

编辑:解决方案

老实说,答案是如此愚蠢和明显:错误是由 +pre-hooks: 而不是 +pre-hook: 引起的。然而,建议的答案让我重新看了一下。我将它标记为正确的,因为它提供了很多关于钩子(Hook)的有用上下文。干杯!

最佳答案

第一印象 - 也许您混淆了特定模型的 model pre-hook 和 run pre-hook 应该放在哪里?

编辑:在上面纠正自己 - Asker 正在尝试执行模型配置预 Hook ,而不是运行预 Hook 。我现在相信您需要将您的预 Hook 移动到与您的命名空间配置相同的优先级别。见下文:

dbt_project.yml

# A run pre-hook that applies to all runs would go here:
on-run-start:
- "{{ example_pre_run_macro() }}"


models:
# a pre-hooks to all models goes here *before* but equivalent depth to the namespace:
+pre-hook: "{{ incremental_failsafe() }}"

namespace:
# Below configures models found in models/events/
events:
+enabled: true
+materialized: view
# a pre-hook to a single model / model directory goes here:
+pre-hook: "{{ example_pre_model_macro() }}"

GitLab 的 dbt 存储库是如何设置所有这些的一个很好的例子:Gitlab dbt_project.yml

TLDR:像这样设置你的 dbt_project.yml

# gold/dbt_project.yml

config-version: 2

...

models:
+pre-hook: "{{ incremental_failsafe() }}"
gold:
<models config here>

关于dbt pre-hooks 无法呈现/查找宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63604372/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com