Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the database when deciding if two tables are the same (#1708) #1774

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions core/dbt/contracts/graph/compiled.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from dbt.contracts.graph.parsed import (
ParsedNode,
ParsedAnalysisNode,
ParsedDocumentation,
ParsedMacro,
ParsedModelNode,
ParsedHookNode,
ParsedRPCNode,
Expand Down Expand Up @@ -216,8 +214,6 @@ def parsed_instance_for(compiled: CompiledNode) -> ParsedNode:
CompiledSnapshotNode,
CompiledTestNode,
ParsedAnalysisNode,
ParsedDocumentation,
ParsedMacro,
ParsedModelNode,
ParsedHookNode,
ParsedRPCNode,
Expand Down
32 changes: 0 additions & 32 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,38 +367,6 @@ def get_resource_fqns(self):

return resource_fqns

def _filter_subgraph(self, subgraph, predicate):
"""
Given a subgraph of the manifest, and a predicate, filter
the subgraph using that predicate. Generates a list of nodes.
"""
to_return = []

for unique_id, item in subgraph.items():
if predicate(item):
to_return.append(item)

return to_return

def _model_matches_schema_and_table(self, schema, table, model):
if model.resource_type == NodeType.Source:
return (model.schema.lower() == schema.lower() and
model.identifier.lower() == table.lower())
return (model.schema.lower() == schema.lower() and
model.alias.lower() == table.lower())

def get_unique_ids_for_schema_and_table(self, schema, table):
"""
Given a schema and table, find matching models, and return
their unique_ids. A schema and table may have more than one
match if the relation matches both a source and a seed, for instance.
"""
def predicate(model):
return self._model_matches_schema_and_table(schema, table, model)

matching = list(self._filter_subgraph(self.nodes, predicate))
return [match.unique_id for match in matching]

def add_nodes(self, new_nodes):
"""Add the given dict of new nodes to the manifest."""
for unique_id, node in new_nodes.items():
Expand Down
4 changes: 4 additions & 0 deletions core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ class ParsedNodeMandatory(
):
alias: str

@property
def identifier(self):
return self.alias


@dataclass
class ParsedNodeDefaults(ParsedNodeMandatory):
Expand Down
8 changes: 4 additions & 4 deletions core/dbt/helper_types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# never name this package "types", or mypy will crash in ugly ways
from datetime import timedelta
from typing import NewType

from hologram import (
FieldEncoder, JsonSchemaMixin, JsonDict, ValidationError
)

from datetime import timedelta
from typing import NewType


Port = NewType('Port', int)

Expand Down Expand Up @@ -39,5 +39,5 @@ def json_schema(self) -> JsonDict:

JsonSchemaMixin.register_field_encoders({
Port: PortEncoder(),
timedelta: TimeDeltaFieldEncoder()
timedelta: TimeDeltaFieldEncoder(),
})
Loading