Search in sources :

Example 1 with ApplyBiFunction

use of uk.gov.gchq.koryphe.impl.function.ApplyBiFunction in project Gaffer by gchq.

the class GetAllElementsIT method shouldAllowBiFunctionInView.

@Test
@TraitRequirement({ StoreTrait.TRANSFORMATION })
public void shouldAllowBiFunctionInView() throws OperationException {
    final Map<String, Class<?>> transientProperties = new HashMap<>();
    transientProperties.put("propLong", Long.class);
    transientProperties.put("combined", Long.class);
    final List<TupleAdaptedFunction<String, ?, ?>> transformFunctions = new ArrayList<>();
    final TupleAdaptedFunction<String, Integer, Long> convertToLong = new TupleAdaptedFunction<>();
    convertToLong.setSelection(new String[] { TestPropertyNames.INT });
    convertToLong.setFunction((Function) new ToLong());
    convertToLong.setProjection(new String[] { "propLong" });
    final TupleAdaptedFunction<String, Integer, Long> sum = new TupleAdaptedFunction<>();
    sum.setSelection(new String[] { "propLong", TestPropertyNames.COUNT });
    sum.setFunction(new ApplyBiFunction(new Sum()));
    sum.setProjection(new String[] { "combined" });
    transformFunctions.add(convertToLong);
    transformFunctions.add(sum);
    final GetAllElements get = new GetAllElements.Builder().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().transientProperties(transientProperties).addTransformFunctions(transformFunctions).build()).build()).build();
    final CloseableIterable<? extends Element> results = graph.execute(get, user);
    for (final Element result : results) {
        final Long expectedResult = (Long) result.getProperty("propLong") + (Long) result.getProperty(TestPropertyNames.COUNT);
        final Long combined = (Long) result.getProperty("combined");
        assertThat(combined).isEqualTo(expectedResult);
    }
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) HashMap(java.util.HashMap) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) ApplyBiFunction(uk.gov.gchq.koryphe.impl.function.ApplyBiFunction) TupleAdaptedFunction(uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction) Sum(uk.gov.gchq.koryphe.impl.binaryoperator.Sum) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)1 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)1 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)1 Sum (uk.gov.gchq.koryphe.impl.binaryoperator.Sum)1 ApplyBiFunction (uk.gov.gchq.koryphe.impl.function.ApplyBiFunction)1 ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)1 TupleAdaptedFunction (uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction)1