英文:
dbt check if the model is table or view
问题
我需要验证在应用逻辑于某列之前,dbt 中正在处理的模型是视图还是宏。
英文:
I had a need to verify if the model being worked is view or macro in dbt before applying a logic on a column.
答案1
得分: 1
我已使用dbt jinja模板来解决这个问题
{%- set relation = load_relation(this) -%}
{%- if relation.is_table -%}
alter table if exists {{this}} modify column {{column_name}} ...;
{%- elif relation is not none and relation.is_view -%}
alter view {{this}} modify column {{column_name}} ...;
{%- endif -%}
英文:
I have used dbt jinja templates to solve this
{%- set relation = load_relation(this) -%}
{%- if relation.is_table -%}
alter table if exists {{this}} modify column {{column_name}} ...;
{%- elif relation is not none and relation.is_view -%}
alter view {{this}} modify column {{column_name}} ...;
{%- endif -%}
答案2
得分: 0
`config`对象具有物化信息。您可以直接从那里查找。
{%- set materialization = config.get('materialized') -%}
值可以是`table`、`view`、`incremental`或`ephemeral`之一。
英文:
The config
object has the materialization. You can look it up directly from there.
{%- set materialization = config.get('materialized') -%}
Value will be one of table
, view
, incremental
, or ephemeral
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论