Search in sources :

Example 21 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class Filter method cloneFunctions.

/**
     * Create a deep copy of the {@link uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext}s executed by this
     * <code>Filter</code>.
     *
     * @return Deep copy of {@link uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext}s.
     */
protected List<ConsumerFunctionContext<R, FilterFunction>> cloneFunctions() {
    final List<ConsumerFunctionContext<R, FilterFunction>> functionClones = new ArrayList<>();
    for (final ConsumerFunctionContext<R, FilterFunction> function : functions) {
        final ConsumerFunctionContext<R, FilterFunction> cloneContext = new ConsumerFunctionContext<>();
        cloneContext.setSelection(function.getSelection());
        final FilterFunction af = function.getFunction();
        if (af != null) {
            cloneContext.setFunction(af.statelessClone());
        }
        functionClones.add(cloneContext);
    }
    return functionClones;
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) ArrayList(java.util.ArrayList)

Example 22 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class FilterTest method shouldBuildFilter.

@Test
public void shouldBuildFilter() {
    // Given
    final String reference1 = "reference 1";
    final String reference2 = "reference 2";
    final String reference3a = "reference 3a";
    final String reference3b = "reference 3b";
    final String reference5 = "reference 5";
    final FilterFunction func1 = mock(FilterFunction.class);
    final FilterFunction func3 = mock(FilterFunction.class);
    final FilterFunction func4 = mock(FilterFunction.class);
    final FilterFunction func5 = mock(FilterFunction.class);
    // When - check you can build the selection/function in any order,
    // although normally it will be done - select then execute.
    final Filter<String> filter = new Filter.Builder<String>().select(reference1).execute(func1).select(reference2).select(new String[] { reference3a, reference3b }).execute(func3).execute(func4).execute(func5).select(reference5).build();
    // Then
    int i = 0;
    ConsumerFunctionContext<String, FilterFunction> context = filter.getFunctions().get(i++);
    assertEquals(1, context.getSelection().size());
    assertEquals(reference1, context.getSelection().get(0));
    assertSame(func1, context.getFunction());
    context = filter.getFunctions().get(i++);
    assertEquals(1, context.getSelection().size());
    assertEquals(reference2, context.getSelection().get(0));
    context = filter.getFunctions().get(i++);
    assertEquals(2, context.getSelection().size());
    assertEquals(reference3a, context.getSelection().get(0));
    assertEquals(reference3b, context.getSelection().get(1));
    assertSame(func3, context.getFunction());
    context = filter.getFunctions().get(i++);
    assertSame(func4, context.getFunction());
    context = filter.getFunctions().get(i++);
    assertSame(func5, context.getFunction());
    assertEquals(1, context.getSelection().size());
    assertEquals(reference5, context.getSelection().get(0));
    assertEquals(i, filter.getFunctions().size());
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) Test(org.junit.Test)

Aggregations

FilterFunction (uk.gov.gchq.gaffer.function.FilterFunction)22 Test (org.junit.Test)14 FilterFunctionTest (uk.gov.gchq.gaffer.function.FilterFunctionTest)11 ConsumerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext)6 ArrayTuple (uk.gov.gchq.gaffer.function.ArrayTuple)4 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)4 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 And (uk.gov.gchq.gaffer.function.filter.And)2 Or (uk.gov.gchq.gaffer.function.filter.Or)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 HashMap (java.util.HashMap)1 InputMismatchException (java.util.InputMismatchException)1 List (java.util.List)1 Set (java.util.Set)1 Filter (org.apache.spark.sql.sources.Filter)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 ElementTuple (uk.gov.gchq.gaffer.data.element.ElementTuple)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1