mirror of
https://github.com/FlipsideCrypto/fsc-utils.git
synced 2026-02-06 10:56:49 +00:00
update existing
This commit is contained in:
parent
e31b50e52d
commit
f76f2e8f89
@ -1,11 +1,37 @@
|
||||
{% macro set_query_tag() -%}
|
||||
{% set new_json = {"repo":project_name, "object":this.table, "profile":target.profile_name, "env":target.name, "existing_tag":get_current_query_tag() } %}
|
||||
{% set new_query_tag = tojson(new_json) | as_text %}
|
||||
{% if new_query_tag %}
|
||||
{% set original_query_tag = get_current_query_tag() %}
|
||||
{{ log("Setting query_tag to '" ~ new_query_tag ~ "'. Will reset to '" ~ original_query_tag ~ "' after materialization.") }}
|
||||
{% do run_query("alter session set query_tag = '{}'".format(new_query_tag)) %}
|
||||
{{ return(original_query_tag)}}
|
||||
{% endif %}
|
||||
{{ return(none)}}
|
||||
{% macro get_query_tag() %}
|
||||
{# Get the full path of the model #}
|
||||
{% set model_path = model.path | string %}
|
||||
{% set folder_path = '/'.join(model_path.split('/')[:-1]) %}
|
||||
|
||||
{# Get core folders from vars #}
|
||||
{% set core_folders = var('core_folders') %}
|
||||
|
||||
{# Initialize is_core and check each path pattern #}
|
||||
{% set ns = namespace(is_core=false) %}
|
||||
|
||||
{% for folder in core_folders %}
|
||||
{% if folder in folder_path %}
|
||||
{% set ns.is_core = true %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{# Build the JSON query tag #}
|
||||
{% set tag_dict = {
|
||||
"project": project_name,
|
||||
"model": model.name,
|
||||
"model_type": "core" if ns.is_core else "non_core",
|
||||
"invocation_id": invocation_id,
|
||||
"dbt_tags": config.get('tags', [])
|
||||
} %}
|
||||
|
||||
{% set query_tag = tojson(tag_dict) %}
|
||||
|
||||
{# Return the properly escaped string #}
|
||||
{{ return("'" ~ query_tag ~ "'") }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro set_query_tag() %}
|
||||
{% set tag = get_query_tag() %}
|
||||
{% do run_query("alter session set query_tag = " ~ tag) %}
|
||||
{{ return("") }}
|
||||
{% endmacro %}
|
||||
@ -1,37 +0,0 @@
|
||||
{% macro get_query_tag() %}
|
||||
{# Get the full path of the model #}
|
||||
{% set model_path = model.path | string %}
|
||||
{% set folder_path = '/'.join(model_path.split('/')[:-1]) %}
|
||||
|
||||
{# Get core folders from vars #}
|
||||
{% set core_folders = var('core_folders') %}
|
||||
|
||||
{# Initialize is_core and check each path pattern #}
|
||||
{% set ns = namespace(is_core=false) %}
|
||||
|
||||
{% for folder in core_folders %}
|
||||
{% if folder in folder_path %}
|
||||
{% set ns.is_core = true %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{# Build the JSON query tag #}
|
||||
{% set tag_dict = {
|
||||
"project": project_name,
|
||||
"model": model.name,
|
||||
"model_type": "core" if ns.is_core else "non_core",
|
||||
"invocation_id": invocation_id,
|
||||
"dbt_tags": config.get('tags', [])
|
||||
} %}
|
||||
|
||||
{% set query_tag = tojson(tag_dict) %}
|
||||
|
||||
{# Return the properly escaped string #}
|
||||
{{ return("'" ~ query_tag ~ "'") }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro set_query_tag() %}
|
||||
{% set tag = get_query_tag() %}
|
||||
{% do run_query("alter session set query_tag = " ~ tag) %}
|
||||
{{ return("") }}
|
||||
{% endmacro %}
|
||||
Loading…
Reference in New Issue
Block a user