Skip to content

Commit

Permalink
Merge pull request #1408 from fishtown-analytics/fix/remove-sql_where…
Browse files Browse the repository at this point in the history
…-from-subquery

Remove sql_where
  • Loading branch information
beckjake committed Apr 23, 2019
2 parents dd469ad + 0885be1 commit 32f74b6
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 42 deletions.
11 changes: 0 additions & 11 deletions core/dbt/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ class DBTRepositoriesDeprecation(DBTDeprecation):
"""


class SqlWhereDeprecation(DBTDeprecation):
name = "sql_where"
description = """\
The `sql_where` option for incremental models is deprecated and will be
removed in a future release. Check the docs for more information
{}
""".format(dbt.links.IncrementalDocs)


class SeedDropExistingDeprecation(DBTDeprecation):
name = 'drop-existing'
description = """The --drop-existing argument to `dbt seed` has been
Expand Down Expand Up @@ -83,7 +73,6 @@ def warn(name, *args, **kwargs):
deprecations_list = [
DBTRepositoriesDeprecation(),
SeedDropExistingDeprecation(),
SqlWhereDeprecation(),
]

deprecations = {d.name: d for d in deprecations_list}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
{%- endmacro %}

{% materialization incremental, default -%}
{%- set sql_where = config.get('sql_where') -%}
{%- set unique_key = config.get('unique_key') -%}

{%- set identifier = model['alias'] -%}
Expand Down Expand Up @@ -57,19 +56,7 @@
{%- else -%}
{%- call statement() -%}

{% set tmp_table_sql -%}
{# We are using a subselect instead of a CTE here to allow PostgreSQL to use indexes. -#}
select * from (
{{ sql }}
) as dbt_incr_sbq

{% if sql_where %}
where ({{ sql_where }})
or ({{ sql_where }}) is null
{% endif %}
{%- endset %}

{{ dbt.create_table_as(True, tmp_relation, tmp_table_sql) }}
{{ dbt.create_table_as(True, tmp_relation, sql) }}

{%- endcall -%}

Expand Down
2 changes: 0 additions & 2 deletions core/dbt/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ def _warn_for_unused_resource_config_paths(manifest, config):
def _warn_for_deprecated_configs(manifest):
for unique_id, node in manifest.nodes.items():
is_model = node.resource_type == NodeType.Model
if is_model and 'sql_where' in node.config:
deprecations.warn('sql_where')


def _check_manifest(manifest, config):
Expand Down
1 change: 0 additions & 1 deletion core/dbt/parser/source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class SourceConfig(object):
'schema',
'enabled',
'materialized',
'sql_where',
'unique_key',
'database',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% materialization incremental, adapter='bigquery' -%}

{%- set unique_key = config.get('unique_key') -%}
{%- set sql_where = config.get('sql_where') -%}

{%- set non_destructive_mode = (flags.NON_DESTRUCTIVE == True) -%}
{%- set full_refresh_mode = (flags.FULL_REFRESH == True) -%}
Expand Down Expand Up @@ -34,12 +33,7 @@
{% set source_sql -%}
{#-- wrap sql in parens to make it a subquery --#}
(
select * from (
{{ sql }}
)
{% if sql_where %}
where ({{ sql_where }}) or ({{ sql_where }}) is null
{% endif %}
{{ sql }}
)
{%- endset -%}

Expand Down
3 changes: 0 additions & 3 deletions test/integration/012_deprecation_tests/models/sql_where.sql

This file was deleted.

4 changes: 2 additions & 2 deletions test/integration/012_deprecation_tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ def test_postgres_deprecations_fail(self):
@use_profile('postgres')
def test_postgres_deprecations(self):
self.assertEqual(deprecations.active_deprecations, set())
results = self.run_dbt(strict=False)
self.assertEqual({'adapter:already_exists', 'sql_where'},
self.run_dbt(strict=False)
self.assertEqual({'adapter:already_exists'},
deprecations.active_deprecations)
1 change: 0 additions & 1 deletion test/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def temp_cd(path):
'sort': 'timestamp',
'materialized': 'incremental',
'dist': 'user_id',
'sql_where': 'created_at > (select max(created_at) from {{ this }})',
'unique_key': 'id'
},
'base': {
Expand Down
1 change: 0 additions & 1 deletion test/unit/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def test__model_incremental(self):
"test_models_compile": {
"model_one": {
"materialized": "incremental",
"sql_where": "created_at",
"unique_key": "id"
},
}
Expand Down

0 comments on commit 32f74b6

Please sign in to comment.