Skip to content

Commit

Permalink
Implement relations api (#727)
Browse files Browse the repository at this point in the history
automatic commit by git-black, original commits:
  5344f54
  • Loading branch information
cmcarthur authored and iknox-fa committed Feb 8, 2022
1 parent d0c159e commit 76088f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
23 changes: 15 additions & 8 deletions core/dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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,
)
Expand Down
33 changes: 16 additions & 17 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/links.py
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 76088f5

Please sign in to comment.