Skip to content

Commit

Permalink
Merge branch 'master' into unpivot-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Campana authored and Alex Campana committed Oct 8, 2018
2 parents d32ce76 + d0a90fe commit 0083a57
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 15 deletions.
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
command: |
python3 -m venv venv
. venv/bin/activate
pip install dbt
mkdir -p ~/.dbt
cp integration_tests/ci/sample.profiles.yml ~/.dbt/profiles.yml
Expand All @@ -33,8 +35,8 @@ jobs:
. venv/bin/activate
cd integration_tests
dbt deps
dbt seed
dbt run
dbt seed --full-refresh
dbt run --full-refresh
dbt test
- save_cache:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Usage:
```

#### star ([source](macros/sql/star.sql))
This macro generates a list of all fields that exist in the `from` relation, excluding any fields listed in the `except` argument. The construction is identical to `select * from {{ref('my_model')}}`, replacing star (`*`) with the star macro.
This macro generates a list of all fields that exist in the `from` relation, excluding any fields listed in the `except` argument. The construction is identical to `select * from {{ref('my_model')}}`, replacing star (`*`) with the star macro. This macro also has an optional `relation_alias` argument that will prefix all generated fields with an alias.

Usage:
```
Expand Down
16 changes: 8 additions & 8 deletions integration_tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

test-postgres:
dbt seed --target postgres
dbt run --target postgres
dbt seed --target postgres --full-refresh
dbt run --target postgres --full-refresh
dbt test --target postgres

test-redshift:
dbt seed --target redshift
dbt run --target redshift
dbt seed --target redshift --full-refresh
dbt run --target redshift --full-refresh
dbt test --target redshift

test-snowflake:
dbt seed --target snowflake
dbt run --target snowflake
dbt seed --target snowflake --full-refresh
dbt run --target snowflake --full-refresh
dbt test --target snowflake

test-bigquery:
dbt seed --target bigquery
dbt run --target bigquery
dbt seed --target bigquery --full-refresh
dbt run --target bigquery --full-refresh
dbt test --target bigquery

test-all: test-postgres test-redshift test-snowflake test-bigquery
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/data/sql/data_union_expected.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,name,favorite_color
1,"drew",
2,"bob",
3,"alice",
1,,"green"
2,,"pink"
4 changes: 4 additions & 0 deletions integration_tests/data/sql/data_union_table_1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name
1,drew
2,bob
3,alice
3 changes: 3 additions & 0 deletions integration_tests/data/sql/data_union_table_2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,favorite_color
1,green
2,pink
5 changes: 5 additions & 0 deletions integration_tests/models/sql/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ test_surrogate_key:
constraints:
assert_equal:
- {actual: actual, expected: expected}

test_union:
constraints:
dbt_utils.equality:
- ref('data_union_expected')
1 change: 1 addition & 0 deletions integration_tests/models/sql/test_get_column_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


select
{% set columns = columns if columns is iterable else [] %}
{% for column in columns -%}

sum(case when field = '{{ column }}' then 1 else 0 end) as count_{{ column }}
Expand Down
8 changes: 8 additions & 0 deletions integration_tests/models/sql/test_union.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

select
id,
name,
favorite_color

from {{ ref('test_union_base') }}

6 changes: 6 additions & 0 deletions integration_tests/models/sql/test_union_base.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

{{ dbt_utils.union_tables([
ref('data_union_table_1'),
ref('data_union_table_2')]
) }}

8 changes: 8 additions & 0 deletions macros/cross_db_utils/literal.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

{% macro string_literal(value) %}
{{ adapter_macro('dbt_utils.string_literal', value) }}
{% endmacro %}

{% macro default__string_literal(value) -%}
'{{ value }}'
{%- endmacro %}
4 changes: 2 additions & 2 deletions macros/sql/star.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro star(from, except=[]) -%}
{% macro star(from, relation_alias=False, except=[]) -%}

{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}
{%- if not execute -%}
Expand All @@ -23,7 +23,7 @@

{%- for col in include_cols %}

"{{ col }}" {% if not loop.last %},
{% if relation_alias %} {{ relation_alias }}.{% endif %}"{{ col }}" {% if not loop.last %},
{% endif %}

{%- endfor -%}
Expand Down
4 changes: 2 additions & 2 deletions macros/sql/union.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
(
select

'{{ table }}'::text as _dbt_source_table,
{{ dbt_utils.safe_cast(dbt_utils.string_literal(table), dbt_utils.type_string()) }} as _dbt_source_table,

{% for col_name in ordered_column_names -%}

{%- set col = column_superset[col_name] %}
{%- set col_type = column_override.get(col.column, col.data_type) %}
{%- set col_name = adapter.quote(col_name) if col_name in table_columns[table] else 'null' %}

{{ col_name }}::{{ col_type }} as {{ col.quoted }} {% if not loop.last %},{% endif %}
{{ dbt_utils.safe_cast(col_name, col_type) }} as {{ col.quoted }} {% if not loop.last %},{% endif %}
{%- endfor %}

from {{ table }}
Expand Down

0 comments on commit 0083a57

Please sign in to comment.