Files
dbt-project-evaluator/macros/get_directory_pattern.sql
2024-09-02 16:33:21 +02:00

34 lines
1.2 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- these macros will read a users home environment and detect whether a computers operating system is Windows based or Mac/Linux, and display the right directory pattern.
{% macro is_os_mac_or_linux() %}
{% for val in graph.nodes.values() %}
{{ return("\\" not in val.get("original_file_path","")) }}
{% endfor %}
{{ return(true) }}
{% endmacro %}
{% macro get_directory_pattern() %}
{% if execute %}
{%- set on_mac_or_linux = dbt_project_evaluator.is_os_mac_or_linux() -%}
{%- if on_mac_or_linux -%}
{{ return("/") }}
{% else %}
{{ return("\\\\") }}
{% endif %}
{% endif %}
{% endmacro %}
{% macro get_regexp_directory_pattern() %}
{% set regexp_escaped = get_directory_pattern() | replace("\\\\", "\\\\\\\\") %}
{% do return(regexp_escaped) %}
{% endmacro %}
{% macro get_dbtreplace_directory_pattern() %}
{% if execute %}
{%- set on_mac_or_linux = dbt_project_evaluator.is_os_mac_or_linux() -%}
{%- if on_mac_or_linux -%}
{{ dbt.replace("file_path", "regexp_replace(file_path,'.*/','')", "''") }}
{% else %}
{{ dbt.replace("file_path", "regexp_replace(file_path,'.*\\\\\\\\','')", "''") }}
{% endif %}
{% endif %}
{% endmacro %}