Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
gh-981: Binary operators added
Browse files Browse the repository at this point in the history
  • Loading branch information
t92549 committed Jul 13, 2022
1 parent 6c6ae9c commit 77acde0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 31 deletions.
2 changes: 2 additions & 0 deletions python-shell/src/fishbowl/fishbowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def _generate_library(self):
operations_python = self._generate_operations()
functions_python = self._generate_transform_functions()
predicates_python = self._generate_filter_functions()
binary_operators_python = self._generate_aggregation_functions()

self._write_to_file(os.path.join(self.generated_directory_path, "functions.py"), functions_python)
self._write_to_file(os.path.join(self.generated_directory_path, "predicates.py"), predicates_python)
self._write_to_file(os.path.join(self.generated_directory_path, "binary_operators.py"), binary_operators_python)
self._write_to_file(os.path.join(self.generated_directory_path, "operations.py"), operations_python)
self._write_to_file(os.path.join(self.generated_directory_path, "__init__.py"),
"__all__ = [ \"operations\", \"predicates\", \"functions\" ]\n")
Expand Down
51 changes: 26 additions & 25 deletions python-shell/src/gafferpy/gaffer_binaryoperators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,45 @@ def to_json(self):
return function_json


class Sum(AbstractBinaryOperator):
CLASS = "uk.gov.gchq.koryphe.impl.binaryoperator.Sum"
# class Sum(AbstractBinaryOperator):
# CLASS = "uk.gov.gchq.koryphe.impl.binaryoperator.Sum"

def __init__(self):
super().__init__(_class_name=self.CLASS)
# def __init__(self):
# super().__init__(_class_name=self.CLASS)

def to_json(self):
return super().to_json()
# def to_json(self):
# return super().to_json()


class Max(AbstractBinaryOperator):
CLASS = "uk.gov.gchq.koryphe.impl.binaryoperator.Max"
# class Max(AbstractBinaryOperator):
# CLASS = "uk.gov.gchq.koryphe.impl.binaryoperator.Max"

def __init__(self):
super().__init__(_class_name=self.CLASS)
# def __init__(self):
# super().__init__(_class_name=self.CLASS)

def to_json(self):
return super().to_json()
# def to_json(self):
# return super().to_json()


class Min(AbstractBinaryOperator):
CLASS = "uk.gov.gchq.koryphe.impl.binaryoperator.Min"
# class Min(AbstractBinaryOperator):
# CLASS = "uk.gov.gchq.koryphe.impl.binaryoperator.Min"

def __init__(self):
super().__init__(_class_name=self.CLASS)
# def __init__(self):
# super().__init__(_class_name=self.CLASS)

def to_json(self):
return super().to_json()
# def to_json(self):
# return super().to_json()

class CollectionConcat(AbstractBinaryOperator):
CLASS = "uk.gov.gchq.koryphe.impl.binaryoperator.CollectionConcat"
# class CollectionConcat(AbstractBinaryOperator):
# CLASS = "uk.gov.gchq.koryphe.impl.binaryoperator.CollectionConcat"

def __init__(self):
super().__init__(_class_name=self.CLASS)
# def __init__(self):
# super().__init__(_class_name=self.CLASS)

def to_json(self):
return super().to_json()
# def to_json(self):
# return super().to_json()

from .generated.binary_operators import *

class BinaryOperatorContext(ToJson, ToCodeString):
CLASS = "gaffer.AggregatorContext"
Expand Down Expand Up @@ -134,7 +136,6 @@ def binary_operator_context_converter(obj):
binary_operator=binary_operator
)


def binary_operator_converter(obj):
if isinstance(obj, dict):
binary_operator = dict(obj)
Expand Down
8 changes: 8 additions & 0 deletions python-shell/src/gafferpy/gaffer_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,14 @@ def to_json(self):
operation_json['entities'][el_def.group] = el_def.to_json()
return operation_json

# List Input
class If(If):
def to_json(self):
operation_json = super().to_json()
if not isinstance(self.input, list):
operation_json["input"] = [self.input]
return operation_json

# Element Input
class GetElements(GetElements):
def to_json(self):
Expand Down
4 changes: 2 additions & 2 deletions python-shell/src/test/test_gaffer_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ class GafferOperationsTest(unittest.TestCase):
selection=[
"count"
],
predicate=g.Or(
predicate=g.pred.Or(
predicates=[
g.IsLessThan(
or_equal_to=False,
Expand Down Expand Up @@ -1536,7 +1536,7 @@ class GafferOperationsTest(unittest.TestCase):
g.ElementDefinition(
pre_aggregation_filter_functions=[
g.PredicateContext(
predicate=g.Or(
predicate=g.pred.Or(
predicates=[
g.NestedPredicate(
predicate=g.IsLessThan(
Expand Down
8 changes: 4 additions & 4 deletions python-shell/src/test/test_gaffer_predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GafferPredicatesTest(unittest.TestCase):
} ]
}
''',
g.And(
g.pred.And(
predicates=[
g.IsLessThan(
value=3,
Expand Down Expand Up @@ -83,7 +83,7 @@ class GafferPredicatesTest(unittest.TestCase):
} ]
}
''',
g.And(
g.pred.And(
predicates=[
g.NestedPredicate(
selection=[
Expand Down Expand Up @@ -372,7 +372,7 @@ class GafferPredicatesTest(unittest.TestCase):
} ]
}
''',
g.Or(
g.pred.Or(
predicates=[
g.IsLessThan(
value=2,
Expand Down Expand Up @@ -411,7 +411,7 @@ class GafferPredicatesTest(unittest.TestCase):
} ]
}
''',
g.Or(
g.pred.Or(
predicates=[
g.NestedPredicate(
selection=[
Expand Down

0 comments on commit 77acde0

Please sign in to comment.