Skip to content

Commit

Permalink
Flake8 refactor node selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Raalsky committed May 7, 2020
1 parent a79ffee commit c481aae
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions core/dbt/graph/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dbt.logger import GLOBAL_LOGGER as logger
from dbt.utils import coalesce
from dbt.node_types import NodeType
from dbt.exceptions import RuntimeException,InternalException, warn_or_error
from dbt.exceptions import RuntimeException, InternalException, warn_or_error

SELECTOR_PARENTS = '+'
SELECTOR_CHILDREN = '+'
Expand Down Expand Up @@ -81,7 +81,10 @@ def __str__(self):

def alert_non_existance(raw_spec, nodes):
if len(nodes) == 0:
warn_or_error(f"The selector '{str(raw_spec)}' does not match any nodes and will be ignored")
warn_or_error(
f"The selector '{str(raw_spec)}' does not match any nodes and will"
f" be ignored"
)


def split_specs(node_specs: Iterable[str]):
Expand Down Expand Up @@ -385,31 +388,47 @@ def get_nodes_from_spec(self, graph, spec):

return collected

def get_nodes_from_multiple_specs(self, graph, specs, selected_nodes=None, check_existence=False, exclude=False):
selected_nodes: Set[str] = coalesce(selected_nodes, set())
def get_nodes_from_multiple_specs(
self,
graph: Graph,
specs: Iterable[str],
nodes: Set[str] = None,
check_existence=False,
exclude=False
):
selected_nodes: Set[str] = coalesce(nodes, set())
operator = set.difference_update if exclude else set.update

for raw_spec in split_specs(specs):
spec = SelectionCriteria(raw_spec)
included_nodes = self.get_nodes_from_spec(graph, spec)
nodes = self.get_nodes_from_spec(graph, spec)

if check_existence:
alert_non_existance(raw_spec, included_nodes)
alert_non_existance(raw_spec, nodes)

operator(selected_nodes, included_nodes)
operator(selected_nodes, nodes)

return selected_nodes

def select_nodes(self, graph, raw_include_specs, raw_exclude_specs):
raw_exclude_specs = coalesce(raw_exclude_specs, [])
check_existance = True

if not raw_include_specs:
check_existance = False
raw_include_specs = ['fqn:*', 'source:*']

selected_nodes = self.get_nodes_from_multiple_specs(graph, raw_include_specs, check_existence=check_existance)
selected_nodes = self.get_nodes_from_multiple_specs(graph, raw_exclude_specs, selected_nodes=selected_nodes,
exclude=True)
selected_nodes = self.get_nodes_from_multiple_specs(
graph,
raw_include_specs,
check_existence=check_existance
)
selected_nodes = self.get_nodes_from_multiple_specs(
graph,
raw_exclude_specs,
nodes=selected_nodes,
exclude=True
)

return selected_nodes

Expand Down

0 comments on commit c481aae

Please sign in to comment.