-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#165
- Loading branch information
Showing
18 changed files
with
323 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
class ExecutionTree: | ||
""" | ||
The execution tree is defined separately to the planner to simplify the | ||
complex code which is the planner from the tree that describes the plan. | ||
""" | ||
|
||
def __init__(self): | ||
"""create empty plan""" | ||
self._nodes: dict = {} | ||
self._edges: list = [] | ||
|
||
def add_operator(self, nid, operator): | ||
""" | ||
Add a step to the DAG | ||
Parameters: | ||
id: string | ||
The id of the step, must be unique | ||
Operator: BaseOperator | ||
The Operator | ||
""" | ||
self._nodes[nid] = operator | ||
|
||
def link_operators(self, source_operator, target_operator, direction=None): | ||
""" | ||
Link steps in a flow. | ||
Parameters: | ||
source_operator: string | ||
The id of the source step | ||
target_operator: string | ||
The id of the target step | ||
direction: string (optional) | ||
Left/Right/None, the direction of the incoming node | ||
""" | ||
edge = ( | ||
source_operator, | ||
target_operator, | ||
direction, | ||
) | ||
if edge not in self._edges: | ||
self._edges.append(edge) | ||
|
||
def get_outgoing_links(self, nid): | ||
""" | ||
Get the ids of outgoing nodes from a given step. | ||
Paramters: | ||
name: string | ||
The name of the step to search from | ||
""" | ||
retval = {target for source, target, direction in self._edges if source == nid} | ||
return sorted(retval) | ||
|
||
def get_incoming_links(self, nid): | ||
""" | ||
Get the ids of incoming nodes for a given step. | ||
Paramters: | ||
nid: string | ||
The name of the step to search from | ||
""" | ||
retval = { | ||
( | ||
source, | ||
direction, | ||
) | ||
for source, target, direction in self._edges | ||
if target == nid | ||
} | ||
return sorted(retval) | ||
|
||
def get_exit_points(self): | ||
""" | ||
Get steps in the flow with no outgoing steps. | ||
""" | ||
sources = {source for source, target, direction in self._edges} | ||
retval = ( | ||
target for source, target, direction in self._edges if target not in sources | ||
) | ||
return sorted(retval) | ||
|
||
def get_entry_points(self): | ||
""" | ||
Get steps in the flow with no incoming steps. | ||
""" | ||
if len(self._nodes) == 1: | ||
return list(self._nodes.keys()) | ||
targets = {target for source, target, direction in self._edges} | ||
retval = ( | ||
source for source, target, direction in self._edges if source not in targets | ||
) | ||
return sorted(retval) | ||
|
||
def get_operator(self, nid): | ||
""" | ||
Get the Operator class by id. | ||
Parameters: | ||
nid: string | ||
The id of the step | ||
""" | ||
return self._nodes.get(nid) | ||
|
||
def is_acyclic(self): | ||
""" | ||
Test if the graph is acyclic | ||
""" | ||
# cycle over the graph removing a layer of exits each cycle | ||
# if we have nodes but no exists, we're cyclic | ||
my_edges = self._edges.copy() | ||
|
||
while len(my_edges) > 0: | ||
# find all of the exits | ||
sources = {source for source, target, direction in my_edges} | ||
exits = { | ||
target | ||
for source, target, direction in my_edges | ||
if target not in sources | ||
} | ||
|
||
if len(exits) == 0: | ||
return False | ||
|
||
# remove the exits | ||
new_edges = [ | ||
(source, target, direction) | ||
for source, target, direction in my_edges | ||
if target not in exits | ||
] | ||
my_edges = new_edges | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
MinIo Reader - also works with AWS | ||
""" | ||
from opteryx.exceptions import MissingDependencyError | ||
from opteryx.storage import BaseStorageAdapter | ||
from opteryx.utils import paths | ||
|
||
try: | ||
from minio import Minio # type:ignore | ||
|
||
minio_installed = True | ||
except ImportError: # pragma: no cover | ||
minio_installed = False | ||
|
||
|
||
class MinIoStorage(BaseStorageAdapter): | ||
def __init__(self, end_point: str, access_key: str, secret_key: str, **kwargs): | ||
|
||
if not minio_installed: # pragma: no cover | ||
raise MissingDependencyError( | ||
"`minio` is missing, please install or include in requirements.txt" | ||
) | ||
|
||
super().__init__(**kwargs) | ||
secure = kwargs.get("secure", True) | ||
self.minio = Minio(end_point, access_key, secret_key, secure=secure) | ||
|
||
def get_blob_list(self, partition): | ||
bucket, object_path, _, _ = paths.get_parts(partition) | ||
blobs = self.minio.list_objects( | ||
bucket_name=bucket, prefix=object_path, recursive=True | ||
) | ||
yield from ( | ||
bucket + "/" + blob.object_name | ||
for blob in blobs | ||
if not blob.object_name.endswith("/") | ||
) | ||
|
||
def read_blob(self, blob_name): | ||
import io | ||
|
||
try: | ||
bucket, object_path, name, extension = paths.get_parts(blob_name) | ||
stream = self.minio.get_object(bucket, object_path + name + extension) | ||
return io.BytesIO(stream.read()) | ||
finally: | ||
stream.close() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.