Skip to content

Commit

Permalink
Merge pull request dbt-labs#24 from birdsong/master
Browse files Browse the repository at this point in the history
Add ability to exclude fields in union macro
  • Loading branch information
drewbanin authored May 15, 2018
2 parents df867a7 + c96f662 commit 39b085d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ This macro implements an "outer union." The list of tables provided to this macr

Usage:
```
{{ dbt_utils.union_tables(tables=[ref('table_1'), ref('table_2')], column_override={"some_field": "varchar(100)"}) }}
{{ dbt_utils.union_tables(
tables=[ref('table_1'), ref('table_2')],
column_override={"some_field": "varchar(100)"},
exclude=["some_other_field"]
) }}
```

#### generate_series ([source](macros/sql/generate_series.sql))
Expand Down
8 changes: 7 additions & 1 deletion macros/sql/union.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% macro union_tables(tables, column_override=none) -%}
{% macro union_tables(tables, column_override=none, exclude=none) -%}

{%- set exclude = exclude if exclude is not none else [] %}
{%- set column_override = column_override if column_override is not none else {} %}

{%- set table_columns = {} %}
Expand All @@ -18,6 +19,8 @@
{%- set cols = adapter.get_columns_in_table(schema, table_name) %}
{%- for col in cols -%}

{%- if col.column not in exclude %}

{# update the list of columns in this table #}
{%- set _ = table_columns[table].append(col.column) %}

Expand All @@ -35,6 +38,9 @@
{%- set _ = column_superset.update({col.column: col}) %}

{%- endif -%}

{%- endif -%}

{%- endfor %}
{%- endfor %}

Expand Down

0 comments on commit 39b085d

Please sign in to comment.