【发布时间】:2022-11-18 03:18:08
【问题描述】:
我目前在 DBT 中使用 Jinja 来创建这 3 组,它们都可以正常工作:
{% set value1 %}
select
category1,
category2,
category3,
category4
from {{ ref('table') }}
where category1 = 'value1'
order by category2
{% endset %}
{% set value2 %}
select
category1,
category2,
category3,
category4
from {{ ref('table') }}
where category1 = value2
order by category2
{% endset %}
{% set value3%}
select
category1,
category2,
category3,
category4
from {{ ref('table') }}
where category1 = value3
order by category2
{% endset %}
我想知道是否有一种方法可以通过使用 for 循环来压缩这 3 个集合的创建。
这是我这样做的尝试:
{% set attributes = ('value1', 'value2', 'value3') %}
{% for i in attributes%}
{% set {{i}} %}
select
category1,
category2,
category3,
category4
from {{ ref('table') }}
where category1 = {{i}}
order by category2
{% endset %}
{% endfor %}
我一直在 for 循环中遇到关于集合第一行的错误。我尝试用 for 循环中的语法更改以多种方式编写它,但没有任何效果。我想知道我是否可以重新创建 3 组的输出,这会比写出所有 3 组更屈尊?
【问题讨论】: