Skip to content

Commit

Permalink
multiple ephemeral refs should share a cte (#316)
Browse files Browse the repository at this point in the history
* multiple ephemeral refs should share a cte
* update changelog
  • Loading branch information
drewbanin authored Mar 3, 2017
1 parent 1a101ad commit 8f00831
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Changes

- Graph refactor: fix common issues with load order ([#292](https://github.com/fishtown-analytics/dbt/pull/292))
- Graph refactor: multiple references to an ephemeral models should share a CTE ([#316](https://github.com/fishtown-analytics/dbt/pull/316))
- Refactor: factor out jinja interactions ([#309](https://github.com/fishtown-analytics/dbt/pull/309))
- Speedup: detect cycles at the end of compilation ([#307](https://github.com/fishtown-analytics/dbt/pull/307))
- Speedup: write graph file with gpickle instead of yaml ([#306](https://github.com/fishtown-analytics/dbt/pull/306))
Expand Down
6 changes: 4 additions & 2 deletions dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ def do_ref(*args):

target_model_id = target_model.get('unique_id')

model['depends_on'].append(target_model_id)
if target_model_id not in model['depends_on']:
model['depends_on'].append(target_model_id)

if get_materialization(target_model) == 'ephemeral':
model['extra_cte_ids'].append(target_model_id)
if target_model_id not in model['extra_cte_ids']:
model['extra_cte_ids'].append(target_model_id)
return '__dbt__CTE__{}'.format(target_model.get('name'))
else:
return '"{}"."{}"'.format(schema, target_model.get('name'))
Expand Down
6 changes: 5 additions & 1 deletion test/integration/020_ephemeral_test/models/dependent.sql
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
select * from {{ref('base')}}

-- multiple ephemeral refs should share a cte
select * from {{ref('base')}} where gender = 'Male'
union all
select * from {{ref('base')}} where gender = 'Female'

0 comments on commit 8f00831

Please sign in to comment.