forked from dbt-labs/dbt-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstar.sql
More file actions
51 lines (46 loc) · 2.41 KB
/
Copy pathstar.sql
File metadata and controls
51 lines (46 loc) · 2.41 KB
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
{% macro star(from, relation_alias=False, except=[], prefix='', suffix='', quote_identifiers=True, unquote_aliases=False, rename={}) -%}
{{ return(adapter.dispatch('star', 'dbt_utils')(from, relation_alias, except, prefix, suffix, quote_identifiers, unquote_aliases, rename)) }}
{% endmacro %}
{% macro default__star(from, relation_alias=False, except=[], prefix='', suffix='', quote_identifiers=True, unquote_aliases=False, rename={}) -%}
{%- do dbt_utils._is_relation(from, 'star') -%}
{%- do dbt_utils._is_ephemeral(from, 'star') -%}
{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}
{%- if not execute -%}
{% do return('*') %}
{%- endif -%}
{% set cols = dbt_utils.get_filtered_columns_in_relation(from, except) %}
{%- set rename_lower = {} -%}
{%- for key, val in rename.items() -%}
{%- do rename_lower.update({key.lower(): val}) -%}
{%- endfor -%}
{%- if cols|length <= 0 -%}
{% if flags.WHICH == 'compile' %}
{% set response %}
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
{% endset %}
{% do return(response) %}
{% else %}
{% do return("/* no columns returned from star() macro */") %}
{% endif %}
{%- else -%}
{%- for col in cols %}
{%- if relation_alias %}{{ relation_alias }}.{% else %}{%- endif -%}
{%- if quote_identifiers -%}
{{ adapter.quote(col)|trim }}
{%- if col.lower() in rename_lower %} as {{ rename_lower[col.lower()] }}
{%- elif unquote_aliases %} as {{ (prefix ~ col ~ suffix)|trim }}
{%- elif prefix!='' or suffix!='' %} as {{ adapter.quote(prefix ~ col ~ suffix)|trim }}
{%- endif -%}
{%- else -%}
{{ col|trim }}
{%- if col.lower() in rename_lower %} as {{ rename_lower[col.lower()] }}
{%- elif prefix!='' or suffix!='' %} as {{ (prefix ~ col ~ suffix)|trim }}
{%- endif -%}
{%- endif -%}
{%- if not loop.last %},{{ '\n ' }}{%- endif -%}
{%- endfor -%}
{% endif %}
{%- endmacro %}