检查模型是表格还是视图

huangapple go评论75阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年2月6日 11:48:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75357176.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定