Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add macro to get columns #516

Merged
merged 13 commits into from
Mar 28, 2022
Prev Previous commit
Next Next commit
add output_lower arg
  • Loading branch information
patkearns10 committed Mar 24, 2022
commit b492782f6bffcb0e187cc4ca5a6a7830c94cfd2a
8 changes: 6 additions & 2 deletions macros/sql/get_columns.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro get_columns(from, except=[]) -%}
{% macro get_columns(from, except=[], output_lower=False) -%}
{{ return(adapter.dispatch('get_columns', 'dbt_utils')(from, except)) }}
{% endmacro %}

Expand All @@ -16,7 +16,11 @@
{%- set except = except | map("lower") | list %}
{%- for col in cols -%}
{%- if col.column|lower not in except -%}
{% do include_cols.append(col.column) %}
{%- if not output_lower %}
{% do include_cols.append(col.column) %}
{% else %}
{% do include_cols.append(col.column|lower) %}
{%- endif -%}
{%- endif %}
{%- endfor %}

Expand Down
6 changes: 3 additions & 3 deletions macros/sql/star.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% macro star(from, relation_alias=False, except=[], prefix='', suffix='') -%}
{% macro star(from, relation_alias=False, except=[], prefix='', suffix='', output_lower=False) -%}
{{ return(adapter.dispatch('star', 'dbt_utils')(from, relation_alias, except, prefix, suffix)) }}
{% endmacro %}

{% macro default__star(from, relation_alias=False, except=[], prefix='', suffix='') -%}
{% macro default__star(from, relation_alias=False, except=[], prefix='', suffix='', output_lower=False) -%}
{%- do dbt_utils._is_relation(from, 'star') -%}
{%- do dbt_utils._is_ephemeral(from, 'star') -%}

Expand All @@ -11,7 +11,7 @@
{{ return('') }}
{% endif %}

{%- for col in dbt_utils.get_columns(from, except) %}
{%- for col in dbt_utils.get_columns(from, except, output_lower) %}

{%- if relation_alias %}{{ relation_alias }}.{% else %}{%- endif -%}{{ adapter.quote(col)|trim }} {%- if prefix!='' or suffix!='' -%} as {{ adapter.quote(prefix ~ col ~ suffix)|trim }} {%- endif -%}
{%- if not loop.last %},{{ '\n ' }}{% endif %}
Expand Down