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

fix(operator): relation type check and extract op return types #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions python/knext/knext/operator/op.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied.
from abc import ABC
from typing import List, Dict, Any
from typing import List, Dict, Tuple, Any

import knext.common.cache
from knext.common.schema_helper import SPGTypeName, TripletName
Expand All @@ -27,7 +27,9 @@ class ExtractOp(BaseOp, ABC):
def __init__(self, params: Dict[str, str] = None):
super().__init__(params)

def invoke(self, record: Dict[str, str]) -> List[Dict[str, str]]:
def invoke(
self, record: Dict[str, str]
) -> Tuple[List[Dict[str, str]], List[SPGRecord]]:
raise NotImplementedError(
f"{self.__class__.__name__} need to implement `invoke` method."
)
Expand Down
9 changes: 7 additions & 2 deletions python/knext/knext/operator/spg_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPGTypeName,
PropertyName,
RelationName,
SPGTypeHelper,
)


Expand Down Expand Up @@ -170,6 +171,10 @@ def upsert_relation(
:param value: The updated relation value. # noqa: E501
:type: str
"""
if isinstance(self._spg_type_name, SPGTypeHelper):
if not hasattr(self._spg_type_name, str(relation_name)):
raise KeyError(f"Relation {relation_name} not defined in Schema")

self.relations[relation_name + "#" + object_type_name] = value
return self

Expand All @@ -181,7 +186,7 @@ def upsert_relations(self, relations: Dict[Tuple[RelationName, SPGTypeName], str
:type: dict
"""
for (relation_name, object_type_name), value in relations.items():
self.relations[relation_name + "#" + object_type_name] = value
self.upsert_relation(relation_name, object_type_name, value)
return self

def remove_relation(
Expand All @@ -204,7 +209,7 @@ def remove_relations(self, relation_names: List[Tuple[RelationName, SPGTypeName]
:param relation_names: A list of relation names. # noqa: E501
:type: list
"""
for (relation_name, object_type_name) in relation_names:
for relation_name, object_type_name in relation_names:
self.relations.pop(relation_name + "#" + object_type_name)
return self

Expand Down
Loading