dbt 运行操作来调用具有非字符串参数的宏

问题描述

说我想删除 ajs 架构作为我们开发数据库上的清理活动,而不是作为常规 dbt 工作流程的一部分

dbt run-operation drop_schema --args '{relation: ajs}'

也许我需要将 drop_schema 包装到另一个drop_schema_str(schema_str) 中,其中 schema_str 是架构的字符串,它用于在调用 {{ 1}}?

解决方法

创建这个宏

{% macro drop_schema_str(schema) %}
  {% set relation = api.Relation.create(database=target.database,schema=schema) %}
  {% do drop_schema(relation) %}
{% endmacro %}

然后用

调用它
dbt run-operation drop_schema_str --args '{schema: ajs}'