1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
{# Source: https://github.com/tconbeer/sqlfmt/issues/326 #}
{% macro get_unique_attributes(source_table, node_col) %}
{% set attribute_query %}
select
distinct x.key as attributes
from {{ source_table }} x
where startswith(x.key, '@') -- attributes get parsed as keys that start with '@'
and length(x.key) > 1 -- but keys of just '@' designate the node itself
and regexp_count(x.path, '\\[') > 1 -- we don't need the attributes from the xml root node
and not startswith(x.key, '@xmlns') -- we don't need attributed data about xml namespaces
{% endset %}
{% set results = run_query(attribute_query) %}
{% if execute %}
{% set results_list = results.columns[0].values() %}
{% else %}
{% set results_list = [] %}
{% endif %}
{% for attribute in results_list %}
, get({{ node_col }}, '{{ attribute }}')::varchar(256) as attribute_{{ dbt_utils.slugify(attribute) | replace("@", "") }}
{% endfor %}
{% endmacro %}
)))))__SQLFMT_OUTPUT__(((((
{# Source: https://github.com/tconbeer/sqlfmt/issues/326 #}
{% macro get_unique_attributes(source_table, node_col) %}
{% set attribute_query %}
select
distinct x.key as attributes
from {{ source_table }} x
where startswith(x.key, '@') -- attributes get parsed as keys that start with '@'
and length(x.key) > 1 -- but keys of just '@' designate the node itself
and regexp_count(x.path, '\\[') > 1 -- we don't need the attributes from the xml root node
and not startswith(x.key, '@xmlns') -- we don't need attributed data about xml namespaces
{% endset %}
{% set results = run_query(attribute_query) %}
{% if execute %} {% set results_list = results.columns[0].values() %}
{% else %} {% set results_list = [] %}
{% endif %}
{% for attribute in results_list %}
,
get({{ node_col }}, '{{ attribute }}')::varchar(
256
) as attribute_{{ dbt_utils.slugify(attribute) | replace("@", "") }}
{% endfor %}
{% endmacro %}
|