admin管理员组文章数量:1390192
I'm trying to change the generate_alias_name macro to change the table name of custom generic test results.
For some reason, when I run the test locally, the generate_alias_name is correctly applied and the test result table is created with the correct name as specified down below, but when running with production target, the naming falls back to default naming of table and test name plus a hash.
Where else could the aliasing be defined for prod?
I'm working with dbt Core and BigQuery.
Thanks in advance!
{% macro generate_alias_name(custom_alias_name=none, node=none) -%}
{% set re = modules.re %}
{% set webshop_pattern = '_(shop1|shop2)?$' %}
{% set node_name = node.name %}
-- re.sub returns the unchanged string if no match is found for pattern.
-- Thus, the following will strip the webshop suffix from node names if found.
-- We want to leave it unchanged if target is local, or resource type is seed or test
-- because everything is materialized in the same dataset in these cases.
{%- if target.name != 'local' and node.resource_type not in ('seed', 'test') -%}
{%- set node_name = re.sub(webshop_pattern, '', node_name) -%}
{%- endif -%}
-- If it's a generic test, then add the webshop suffix that's found in the model name to the test result table
-- node.test_metadata is defined -> generic test
{%- if node.resource_type == 'test' and node.test_metadata is defined -%}
{% set model_tested = re.search("ref\('([^']+)'\)", node.test_metadata.kwargs['model']).group(1) %}
{% set search_result = re.search(webshop_pattern, model_tested) %}
{% set webshop_suffix = '' if search_result is none else search_result[0] %}
{% set node_name = node.test_metadata.name ~ webshop_suffix %}
{%- endif -%}
{%- if custom_alias_name -%}
{%- if target.name == 'local' -%}
{{ node_name }}
{%- else -%}
{{ custom_alias_name | trim }}
{%- endif -%}
{%- elif node.version -%}
{{ return(node_name ~ '_v' ~ (node.version | replace('.', '_'))) }}
{%- else -%}
{{ node_name }}
{%- endif -%}
{%- endmacro %}
tldr: I changed the generate_alias_name dbt macro to change the table name of results of generic test. When running the test locally, it applied correctly, when running in prod, it didn't work and went back to default naming.
本文标签: dbt generatealiasname does not apply to generic test running in prod environmentStack Overflow
版权声明:本文标题:dbt: generate_alias_name does not apply to generic test running in prod environment - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744619877a2615957.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论