Skip to content

Commit d0a90fe

Browse files
authored
Merge pull request #82 from fishtown-analytics/bq/union
make union work on bq
2 parents bcbe57c + bf99805 commit d0a90fe

File tree

11 files changed

+55
-12
lines changed

11 files changed

+55
-12
lines changed

.circleci/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ jobs:
1818
command: |
1919
python3 -m venv venv
2020
. venv/bin/activate
21+
2122
pip install dbt
23+
2224
mkdir -p ~/.dbt
2325
cp integration_tests/ci/sample.profiles.yml ~/.dbt/profiles.yml
2426
@@ -33,8 +35,8 @@ jobs:
3335
. venv/bin/activate
3436
cd integration_tests
3537
dbt deps
36-
dbt seed
37-
dbt run
38+
dbt seed --full-refresh
39+
dbt run --full-refresh
3840
dbt test
3941
4042
- save_cache:

integration_tests/Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11

22
test-postgres:
3-
dbt seed --target postgres
4-
dbt run --target postgres
3+
dbt seed --target postgres --full-refresh
4+
dbt run --target postgres --full-refresh
55
dbt test --target postgres
66

77
test-redshift:
8-
dbt seed --target redshift
9-
dbt run --target redshift
8+
dbt seed --target redshift --full-refresh
9+
dbt run --target redshift --full-refresh
1010
dbt test --target redshift
1111

1212
test-snowflake:
13-
dbt seed --target snowflake
14-
dbt run --target snowflake
13+
dbt seed --target snowflake --full-refresh
14+
dbt run --target snowflake --full-refresh
1515
dbt test --target snowflake
1616

1717
test-bigquery:
18-
dbt seed --target bigquery
19-
dbt run --target bigquery
18+
dbt seed --target bigquery --full-refresh
19+
dbt run --target bigquery --full-refresh
2020
dbt test --target bigquery
2121

2222
test-all: test-postgres test-redshift test-snowflake test-bigquery
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
id,name,favorite_color
2+
1,"drew",
3+
2,"bob",
4+
3,"alice",
5+
1,,"green"
6+
2,,"pink"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
id,name
2+
1,drew
3+
2,bob
4+
3,alice
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id,favorite_color
2+
1,green
3+
2,pink

integration_tests/models/sql/schema.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ test_surrogate_key:
5656
constraints:
5757
assert_equal:
5858
- {actual: actual, expected: expected}
59+
60+
test_union:
61+
constraints:
62+
dbt_utils.equality:
63+
- ref('data_union_expected')

integration_tests/models/sql/test_get_column_values.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
select
6+
{% set columns = columns if columns is iterable else [] %}
67
{% for column in columns -%}
78

89
sum(case when field = '{{ column }}' then 1 else 0 end) as count_{{ column }}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
select
3+
id,
4+
name,
5+
favorite_color
6+
7+
from {{ ref('test_union_base') }}
8+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
{{ dbt_utils.union_tables([
3+
ref('data_union_table_1'),
4+
ref('data_union_table_2')]
5+
) }}
6+

macros/cross_db_utils/literal.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
{% macro string_literal(value) %}
3+
{{ adapter_macro('dbt_utils.string_literal', value) }}
4+
{% endmacro %}
5+
6+
{% macro default__string_literal(value) -%}
7+
'{{ value }}'
8+
{%- endmacro %}

macros/sql/union.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@
5656
(
5757
select
5858

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

6161
{% for col_name in ordered_column_names -%}
6262

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

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

7070
from {{ table }}

0 commit comments

Comments
 (0)