From 76088f5951f4cdbf33f714aae5c2a15b0964e795 Mon Sep 17 00:00:00 2001 From: Connor McArthur Date: Thu, 26 Apr 2018 17:38:44 -0400 Subject: [PATCH] Implement relations api (#727) automatic commit by git-black, original commits: 5344f54c3c766b8b7716c0cbe26a78095b7ad9e7 --- core/dbt/adapters/base/relation.py | 23 +++++++++++++-------- core/dbt/exceptions.py | 33 +++++++++++++++--------------- core/dbt/links.py | 2 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/core/dbt/adapters/base/relation.py b/core/dbt/adapters/base/relation.py index e920708a660..3f76b62e4cf 100644 --- a/core/dbt/adapters/base/relation.py +++ b/core/dbt/adapters/base/relation.py @@ -72,16 +72,19 @@ def matches( schema: Optional[str] = None, identifier: Optional[str] = None, ) -> bool: - search = filter_null_values({ + search = filter_null_values( { ComponentName.Database: database, ComponentName.Schema: schema, - }) + ComponentName.Identifier: identifier, + } + ) if not search: # nothing was passed in raise dbt.exceptions.RuntimeException( - "Tried to match relation, but no search path was passed!") + "Tried to match relation, but no search path was passed!" + ) exact_match = True approximate_match = True @@ -113,11 +116,13 @@ def quote( schema: Optional[bool] = None, identifier: Optional[bool] = None, ) -> Self: - policy = filter_null_values({ + policy = filter_null_values( { ComponentName.Database: database, ComponentName.Schema: schema, - }) + ComponentName.Identifier: identifier, + } + ) new_quote_policy = self.quote_policy.replace_dict(policy) return self.replace(quote_policy=new_quote_policy) @@ -128,11 +133,13 @@ def include( schema: Optional[bool] = None, identifier: Optional[bool] = None, ) -> Self: - policy = filter_null_values({ + policy = filter_null_values( { ComponentName.Database: database, ComponentName.Schema: schema, - }) + ComponentName.Identifier: identifier, + } + ) new_include_policy = self.include_policy.replace_dict(policy) return self.replace(include_policy=new_include_policy) @@ -180,7 +187,7 @@ def render(self) -> str: ) def quoted(self, identifier): - return '{quote_char}{identifier}{quote_char}'.format( + return "{quote_char}{identifier}{quote_char}".format( quote_char=self.quote_character, identifier=identifier, ) diff --git a/core/dbt/exceptions.py b/core/dbt/exceptions.py index 2fc16e5e5fe..213a579315b 100644 --- a/core/dbt/exceptions.py +++ b/core/dbt/exceptions.py @@ -735,13 +735,13 @@ def raise_dataclass_not_dict(obj): def relation_wrong_type(relation, expected_type, model=None): raise_compiler_error( - ('Trying to create {expected_type} {relation}, ' - 'but it currently exists as a {current_type}. Either ' - 'drop {relation} manually, or run dbt with ' - '`--full-refresh` and dbt will drop it for you.') - .format(relation=relation, - current_type=relation.type, - expected_type=expected_type), + ( + "Trying to create {expected_type} {relation}, " + "but it currently exists as a {current_type}. Either " + "drop {relation} manually, or run dbt with " + "`--full-refresh` and dbt will drop it for you." + ).format(relation=relation, current_type=relation.type, expected_type=expected_type), + model, model) @@ -790,10 +790,10 @@ def raise_dep_not_found(node, node_description, required_pkg): def multiple_matching_relations(kwargs, matches): raise_compiler_error( - 'get_relation returned more than one relation with the given args. ' - 'Please specify a database or schema to narrow down the result set.' - '\n{}\n\n{}' - .format(kwargs, matches)) + "get_relation returned more than one relation with the given args. " + "Please specify a database or schema to narrow down the result set." + "\n{}\n\n{}".format(kwargs, matches) + ) def get_relation_returned_multiple_results(kwargs, matches): @@ -802,12 +802,11 @@ def get_relation_returned_multiple_results(kwargs, matches): def approximate_relation_match(target, relation): raise_compiler_error( - 'When searching for a relation, dbt found an approximate match. ' - 'Instead of guessing \nwhich relation to use, dbt will move on. ' - 'Please delete {relation}, or rename it to be less ambiguous.' - '\nSearched for: {target}\nFound: {relation}' - .format(target=target, - relation=relation)) + "When searching for a relation, dbt found an approximate match. " + "Instead of guessing \nwhich relation to use, dbt will move on. " + "Please delete {relation}, or rename it to be less ambiguous." + "\nSearched for: {target}\nFound: {relation}".format(target=target, relation=relation) + ) def raise_duplicate_macro_name(node_1, node_2, namespace) -> NoReturn: diff --git a/core/dbt/links.py b/core/dbt/links.py index c934942e391..c38d5cd749c 100644 --- a/core/dbt/links.py +++ b/core/dbt/links.py @@ -1,4 +1,4 @@ ProfileConfigDocs = 'https://docs.getdbt.com/docs/configure-your-profile' -SnowflakeQuotingDocs = 'https://docs.getdbt.com/v0.10/docs/configuring-quoting' +SnowflakeQuotingDocs = "https://docs.getdbt.com/v0.10/docs/configuring-quoting" IncrementalDocs = 'https://docs.getdbt.com/docs/configuring-incremental-models' BigQueryNewPartitionBy = 'https://docs.getdbt.com/docs/upgrading-to-0-16-0'