From 77acde0418d2bdf201699ac69a4ac8b0060dd7a9 Mon Sep 17 00:00:00 2001 From: t92549 <80890692+t92549@users.noreply.github.com> Date: Wed, 13 Jul 2022 12:52:00 +0100 Subject: [PATCH] gh-981: Binary operators added --- python-shell/src/fishbowl/fishbowl.py | 2 + .../src/gafferpy/gaffer_binaryoperators.py | 51 ++++++++++--------- .../src/gafferpy/gaffer_operations.py | 8 +++ .../src/test/test_gaffer_operations.py | 4 +- .../src/test/test_gaffer_predicates.py | 8 +-- 5 files changed, 42 insertions(+), 31 deletions(-) diff --git a/python-shell/src/fishbowl/fishbowl.py b/python-shell/src/fishbowl/fishbowl.py index 7a19de2df..23301bf23 100644 --- a/python-shell/src/fishbowl/fishbowl.py +++ b/python-shell/src/fishbowl/fishbowl.py @@ -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") diff --git a/python-shell/src/gafferpy/gaffer_binaryoperators.py b/python-shell/src/gafferpy/gaffer_binaryoperators.py index a4d8332cf..983b3b453 100755 --- a/python-shell/src/gafferpy/gaffer_binaryoperators.py +++ b/python-shell/src/gafferpy/gaffer_binaryoperators.py @@ -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" @@ -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) diff --git a/python-shell/src/gafferpy/gaffer_operations.py b/python-shell/src/gafferpy/gaffer_operations.py index 04ac001e7..a560bbf19 100755 --- a/python-shell/src/gafferpy/gaffer_operations.py +++ b/python-shell/src/gafferpy/gaffer_operations.py @@ -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): diff --git a/python-shell/src/test/test_gaffer_operations.py b/python-shell/src/test/test_gaffer_operations.py index 98fdbeb15..4c59b3124 100755 --- a/python-shell/src/test/test_gaffer_operations.py +++ b/python-shell/src/test/test_gaffer_operations.py @@ -1459,7 +1459,7 @@ class GafferOperationsTest(unittest.TestCase): selection=[ "count" ], - predicate=g.Or( + predicate=g.pred.Or( predicates=[ g.IsLessThan( or_equal_to=False, @@ -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( diff --git a/python-shell/src/test/test_gaffer_predicates.py b/python-shell/src/test/test_gaffer_predicates.py index 836f0d574..7df1ce52d 100755 --- a/python-shell/src/test/test_gaffer_predicates.py +++ b/python-shell/src/test/test_gaffer_predicates.py @@ -47,7 +47,7 @@ class GafferPredicatesTest(unittest.TestCase): } ] } ''', - g.And( + g.pred.And( predicates=[ g.IsLessThan( value=3, @@ -83,7 +83,7 @@ class GafferPredicatesTest(unittest.TestCase): } ] } ''', - g.And( + g.pred.And( predicates=[ g.NestedPredicate( selection=[ @@ -372,7 +372,7 @@ class GafferPredicatesTest(unittest.TestCase): } ] } ''', - g.Or( + g.pred.Or( predicates=[ g.IsLessThan( value=2, @@ -411,7 +411,7 @@ class GafferPredicatesTest(unittest.TestCase): } ] } ''', - g.Or( + g.pred.Or( predicates=[ g.NestedPredicate( selection=[