Skip to content

Commit

Permalink
Merge branch 'dev/grace-kelly' into dev/stephen-girard
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Dec 5, 2018
2 parents 282774c + bec30ef commit 91a5b1c
Show file tree
Hide file tree
Showing 21 changed files with 389 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.12.1
current_version = 0.12.2a1
parse = (?P<major>\d+)
\.(?P<minor>\d+)
\.(?P<patch>\d+)
Expand Down
13 changes: 13 additions & 0 deletions dbt/adapters/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ def type(self):
'type not implemented for base credentials class'
)

def connection_info(self):
"""Return an ordered iterator of key/value pairs for pretty-printing.
"""
for key in self._connection_keys():
if key in self._contents:
yield key, self._contents[key]

def _connection_keys(self):
"""The credential object keys that should be printed to users in
'dbt debug' output. This is specific to each adapter.
"""
raise NotImplementedError


@six.add_metaclass(abc.ABCMeta)
class BaseConnectionManager(object):
Expand Down
3 changes: 3 additions & 0 deletions dbt/adapters/bigquery/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class BigQueryCredentials(Credentials):
def type(self):
return 'bigquery'

def _connection_keys(self):
return ('method', 'project', 'schema', 'location')


class BigQueryConnectionManager(BaseConnectionManager):
TYPE = 'bigquery'
Expand Down
3 changes: 3 additions & 0 deletions dbt/adapters/postgres/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def password(self):
# we can't access this as 'pass' since that's reserved
return self._contents['pass']

def _connection_keys(self):
return ('host', 'port', 'user', 'dbname', 'schema')


class PostgresConnectionManager(SQLConnectionManager):
DEFAULT_TCP_KEEPALIVE = 0 # 0 means to use the default value
Expand Down
3 changes: 3 additions & 0 deletions dbt/adapters/redshift/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def __init__(self, *args, **kwargs):
def type(self):
return 'redshift'

def _connection_keys(self):
return ('host', 'port', 'user', 'dbname', 'schema', 'method')


class RedshiftConnectionManager(PostgresConnectionManager):
DEFAULT_TCP_KEEPALIVE = 240
Expand Down
3 changes: 3 additions & 0 deletions dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class SnowflakeCredentials(Credentials):
def type(self):
return 'snowflake'

def _connection_keys(self):
return ('account', 'user', 'database', 'schema', 'warehouse', 'role')


class SnowflakeConnectionManager(SQLConnectionManager):
TYPE = 'snowflake'
Expand Down
7 changes: 7 additions & 0 deletions dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ def _check_resource_uniqueness(cls, manifest):
names_resources[name] = node
alias_resources[alias] = node

def warn_for_deprecated_configs(self, 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:
dbt.deprecations.warn('sql_where')

def compile(self):
linker = Linker()

Expand All @@ -247,6 +253,7 @@ def compile(self):
disabled_fqns = [n.fqn for n in manifest.disabled]
self.config.warn_for_unused_resource_config_paths(resource_fqns,
disabled_fqns)
self.warn_for_deprecated_configs(manifest)

self.link_graph(linker, manifest)

Expand Down
12 changes: 6 additions & 6 deletions dbt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def _credentials_from_profile(profile, profile_name, target_name):
return credentials

@staticmethod
def _pick_profile_name(args_profile_name, project_profile_name=None):
def pick_profile_name(args_profile_name, project_profile_name=None):
profile_name = project_profile_name
if args_profile_name is not None:
profile_name = args_profile_name
Expand Down Expand Up @@ -609,8 +609,8 @@ def from_credentials(cls, credentials, threads, profile_name, target_name,
return profile

@classmethod
def _render_profile(cls, raw_profile, profile_name, target_override,
cli_vars):
def render_profile(cls, raw_profile, profile_name, target_override,
cli_vars):
"""This is a containment zone for the hateful way we're rendering
profiles.
"""
Expand Down Expand Up @@ -667,7 +667,7 @@ def from_raw_profile_info(cls, raw_profile, profile_name, cli_vars,
"""
# user_cfg is not rendered since it only contains booleans.
# TODO: should it be, and the values coerced to bool?
target_name, profile_data = cls._render_profile(
target_name, profile_data = cls.render_profile(
raw_profile, profile_name, target_override, cli_vars
)

Expand Down Expand Up @@ -753,8 +753,8 @@ def from_args(cls, args, project_profile_name=None, cli_vars=None):
profiles_dir = getattr(args, 'profiles_dir', PROFILES_DIR)
target_override = getattr(args, 'target', None)
raw_profiles = read_profile(profiles_dir)
profile_name = cls._pick_profile_name(args.profile,
project_profile_name)
profile_name = cls.pick_profile_name(args.profile,
project_profile_name)

return cls.from_raw_profiles(
raw_profiles=raw_profiles,
Expand Down
14 changes: 13 additions & 1 deletion dbt/deprecations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dbt.logger import GLOBAL_LOGGER as logger
import dbt.links


class DBTDeprecation(object):
Expand Down Expand Up @@ -26,6 +27,16 @@ 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 All @@ -50,7 +61,8 @@ def warn(name, *args, **kwargs):

deprecations_list = [
DBTRepositoriesDeprecation(),
SeedDropExistingDeprecation()
SeedDropExistingDeprecation(),
SqlWhereDeprecation(),
]

deprecations = {d.name: d for d in deprecations_list}
Expand Down
10 changes: 10 additions & 0 deletions dbt/include/global_project/macros/etc/is_incremental.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

{% macro is_incremental() %}
{#-- do not run introspective queries in parsing #}
{% if not execute %}
{{ return(False) }}
{% else %}
{% set relation = adapter.get_relation(this.schema, this.table) %}
{{ return(relation is not none and not flags.FULL_REFRESH) }}
{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
select * from (
{{ sql }}
)
where ({{ sql_where }}) or ({{ sql_where }}) is null
{% if sql_where %}
where ({{ sql_where }}) or ({{ sql_where }}) is null
{% endif %}
)
{%- endset -%}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{%- endmacro %}

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

{%- set identifier = model['alias'] -%}
Expand Down Expand Up @@ -61,8 +61,11 @@
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) }}
Expand Down
3 changes: 2 additions & 1 deletion dbt/links.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

ProfileConfigDocs = 'https://docs.getdbt.com/docs/configure-your-profile'
SnowflakeQuotingDocs = 'https://docs.getdbt.com/v0.10/docs/configuring-quoting'
IncrementalDocs = 'https://docs.getdbt.com/docs/configuring-incremental-models'
5 changes: 3 additions & 2 deletions dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def run_from_args(parsed):
task = None
cfg = None

if parsed.which == 'init':
# bypass looking for a project file if we're running `dbt init`
if parsed.which in ('init', 'debug'):
# bypass looking for a project file if we're running `dbt init` or
# `dbt debug`
task = parsed.cls(args=parsed)
else:
nearest_project_dir = get_nearest_project_dir()
Expand Down
Loading

0 comments on commit 91a5b1c

Please sign in to comment.