jinja2 - 无法在 DBT 中的 adapter.get_relation 中使用 Jinja 变量
问题描述
我正在尝试在我的 adapter.get_relation 中使用 Jinja 变量,但我无法这样做:困惑:代码
{% set the_var = 'amazon_full_orders_denormalized_' ~ company_uuid %}
{{ log(the_var, info=True) }}
{%- set source_relation = adapter.get_relation(
database='282615',
schema='airbyte_mumbai',
identifier= the_var ) -%}
我正在使用的命令
dbt compile --vars '{"company_uuid":"0703afd3_496b_4ed5_8e0c_594b71f4718b","dataset":"airbyte_mumbai"}' --models tag:copy_reports
变量 the_var 被设置为amazon_full_orders_denormalized_
Found 6 models, 0 tests, 0 snapshots, 0 analyses, 165 macros, 0 operations, 0 seed files, 0 sources, 0 exposures
17:11:08 | Concurrency: 3 threads (target='dev')
17:11:08 |
amazon_full_orders_denormalized_
Table does not exist
17:11:08 | Done.
而我期望它被设置为amazon_full_orders_denormalized_0703afd3_496b_4ed5_8e0c_594b71f4718b
解决方案
在 dbt 中使用变量有时会很困难!我认为评论者@Kay 在这里是正确的,因为这里发生了三个变量:the_var
、company_uuid
和dataset
。看起来你想要一个表名,它是the_var
and的连接company_uuid
,你可以使用 jinja 的 concat 运算符来做到~
这一点,就像这样:
-- just for testing
{{ log(the_var, info=True) }}
{{ log(var('company_uuid'), info=True) }}
{{ log(the_var ~ var('company_uuid'), info=True) }}
-- see change to `identifier`
{%- set source_relation = adapter.get_relation(
database='282615',
schema='airbyte_mumbai',
identifier= the_var ~ var('company_uuid') ) -%}
推荐阅读
- cytoscape - Cytoscape - 从 CyREST 设置 nodeCustomGraphicsSizeSync 和 nodeSizeLocked
- java - 无法在 AsyncTask 中未调用 Looper.prepare() 的线程内创建处理程序
- mongodb - 使用 Selenium/Java 从 MongoDB 中检索单个字段
- html - 引导 4 容器中卡片翻转的绝对位置
- random-forest - 一棵树的随机森林比一棵决策树的性能差?
- azure-devops - Azure DevOps Services\Server 中部署组和环境之间的区别
- node.js - ClientSession 需要 Mongdb 副本集中的 ServerSessionPool - NODEJS
- python - Within contextlib.redirect_stdout() the print()-function causes an AttributeError: 'str' object has no attribute 'write'
- javascript - vue-select :从 VueJs 中的祖父组件传递选项槽
- reactjs - Ember 应用程序中的状态管理