Search in sources :

Example 1 with ExampleTuple2BinaryOperator

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

the class SchemaElementDefinitionTest method shouldReturnQueryAggregatorWithViewAggregator.

@Test
public void shouldReturnQueryAggregatorWithViewAggregator() {
    // Given
    final T elementDef = createBuilder().property("property1", PROPERTY_STRING_TYPE).property("property2", PROPERTY_STRING_TYPE).property("property3", PROPERTY_STRING_TYPE).property("property4", PROPERTY_STRING_TYPE).property("property5", PROPERTY_STRING_TYPE).property("visibility", PROPERTY_STRING_TYPE).property("timestamp", PROPERTY_STRING_TYPE).groupBy("property1", "property2").aggregator(new ElementAggregator.Builder().select("property3", "property4").execute(new ExampleTuple2BinaryOperator()).build()).build();
    setupSchema(elementDef);
    final ElementAggregator viewAggregator = new ElementAggregator.Builder().select("property1").execute(new StringConcat()).build();
    // When
    final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator);
    // Then
    int i = 0;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof StringConcat);
    assertArrayEquals(new String[] { "property1" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property3", "property4" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property2" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property5" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "visibility" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "timestamp" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertEquals(i, aggregator.getComponents().size());
    // Check the aggregator is locked.
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> aggregator.getComponents().add(null)).isNotNull();
    // check the aggregator is not cached
    assertNotSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator));
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) ExampleTuple2BinaryOperator(uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator) ExampleAggregateFunction(uk.gov.gchq.gaffer.function.ExampleAggregateFunction) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 2 with ExampleTuple2BinaryOperator

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

the class SchemaElementDefinitionTest method shouldReturnQueryAggregatorWithMultiPropertyAggregator.

@Test
public void shouldReturnQueryAggregatorWithMultiPropertyAggregator() {
    // Given
    final T elementDef = createBuilder().property("property1", PROPERTY_STRING_TYPE).property("property2", PROPERTY_STRING_TYPE).property("property3", PROPERTY_STRING_TYPE).property("property4", PROPERTY_STRING_TYPE).property("property5", PROPERTY_STRING_TYPE).property("visibility", PROPERTY_STRING_TYPE).property("timestamp", PROPERTY_STRING_TYPE).groupBy("property1", "property2").aggregator(new ElementAggregator.Builder().select("property1", "property2").execute(new ExampleTuple2BinaryOperator()).select("property3", "property4").execute(new ExampleTuple2BinaryOperator()).build()).build();
    setupSchema(elementDef);
    // When
    final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet(), null);
    // Then
    assertEquals(5, aggregator.getComponents().size());
    assertTrue(aggregator.getComponents().get(0).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property1", "property2" }, aggregator.getComponents().get(0).getSelection());
    assertTrue(aggregator.getComponents().get(1).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property3", "property4" }, aggregator.getComponents().get(1).getSelection());
    assertTrue(aggregator.getComponents().get(2).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property5" }, aggregator.getComponents().get(2).getSelection());
    assertTrue(aggregator.getComponents().get(3).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "visibility" }, aggregator.getComponents().get(3).getSelection());
    assertTrue(aggregator.getComponents().get(4).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "timestamp" }, aggregator.getComponents().get(4).getSelection());
    // Check the aggregator is locked.
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> aggregator.getComponents().add(null)).isNotNull();
    // check the aggregator is cached
    assertSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), null));
}
Also used : ExampleTuple2BinaryOperator(uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator) ExampleAggregateFunction(uk.gov.gchq.gaffer.function.ExampleAggregateFunction) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 3 with ExampleTuple2BinaryOperator

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

the class SchemaElementDefinitionTest method shouldReturnQueryAggregatorWithViewAggregatorAndMultipleAgg.

@Test
public void shouldReturnQueryAggregatorWithViewAggregatorAndMultipleAgg() {
    // Given
    final T elementDef = createBuilder().property("property1", PROPERTY_STRING_TYPE).property("property2", PROPERTY_STRING_TYPE).property("property3", PROPERTY_STRING_TYPE).property("property4", PROPERTY_STRING_TYPE).property("property5", PROPERTY_STRING_TYPE).property("visibility", PROPERTY_STRING_TYPE).property("timestamp", PROPERTY_STRING_TYPE).groupBy("property1", "property2").aggregator(new ElementAggregator.Builder().select("property1", "property2").execute(new ExampleTuple2BinaryOperator()).select("property3", "property4").execute(new ExampleTuple2BinaryOperator()).build()).build();
    setupSchema(elementDef);
    final ElementAggregator viewAggregator = new ElementAggregator.Builder().select("property1").execute(new StringConcat()).build();
    // When
    final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator);
    // Then
    int i = 0;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof StringConcat);
    assertArrayEquals(new String[] { "property1" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property1", "property2" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property3", "property4" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property5" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "visibility" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "timestamp" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertEquals(i, aggregator.getComponents().size());
    // Check the aggregator is locked.
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> aggregator.getComponents().add(null)).isNotNull();
    // check the aggregator is not cached
    assertNotSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator));
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) ExampleTuple2BinaryOperator(uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator) ExampleAggregateFunction(uk.gov.gchq.gaffer.function.ExampleAggregateFunction) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 4 with ExampleTuple2BinaryOperator

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

the class SchemaElementDefinitionTest method shouldReturnFullAggregatorWithMultiPropertyAggregator.

@Test
public void shouldReturnFullAggregatorWithMultiPropertyAggregator() {
    // Given
    final T elementDef = createBuilder().property("property1", PROPERTY_STRING_TYPE).property("property2", PROPERTY_STRING_TYPE).property("property3", PROPERTY_STRING_TYPE).property("property4", PROPERTY_STRING_TYPE).property("property5", PROPERTY_STRING_TYPE).property("visibility", PROPERTY_STRING_TYPE).property("timestamp", PROPERTY_STRING_TYPE).groupBy("property1", "property2").aggregator(new ElementAggregator.Builder().select("property1", "property2").execute(new ExampleTuple2BinaryOperator()).build()).build();
    setupSchema(elementDef);
    // When
    final ElementAggregator aggregator = elementDef.getFullAggregator();
    // Then
    assertEquals(6, aggregator.getComponents().size());
    assertTrue(aggregator.getComponents().get(0).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property1", "property2" }, aggregator.getComponents().get(0).getSelection());
    assertTrue(aggregator.getComponents().get(1).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property3" }, aggregator.getComponents().get(1).getSelection());
    assertTrue(aggregator.getComponents().get(2).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property4" }, aggregator.getComponents().get(2).getSelection());
    assertTrue(aggregator.getComponents().get(3).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property5" }, aggregator.getComponents().get(3).getSelection());
    assertTrue(aggregator.getComponents().get(4).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "visibility" }, aggregator.getComponents().get(4).getSelection());
    assertTrue(aggregator.getComponents().get(5).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "timestamp" }, aggregator.getComponents().get(5).getSelection());
    // Check the aggregator is locked.
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> aggregator.getComponents().add(null)).isNotNull();
    // check the aggregator is cached
    assertSame(aggregator, elementDef.getFullAggregator());
}
Also used : ExampleTuple2BinaryOperator(uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator) ExampleAggregateFunction(uk.gov.gchq.gaffer.function.ExampleAggregateFunction) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 5 with ExampleTuple2BinaryOperator

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

the class ElementAggregatorTest method shouldAggregateWithTuple2BinaryOperator.

@Test
public void shouldAggregateWithTuple2BinaryOperator() {
    // Given
    final String property1 = "property 1";
    final String property2 = "property 2";
    final BinaryOperator func1 = new ExampleTuple2BinaryOperator();
    final ElementAggregator aggregator = new ElementAggregator.Builder().select(property1, property2).execute(func1).build();
    final Properties props1 = new Properties();
    props1.put(property1, 1);
    props1.put(property2, "value1");
    final Properties props2 = new Properties();
    props2.put(property1, 10);
    props2.put(property2, "value10");
    final Properties props3 = new Properties();
    props3.put(property1, 5);
    props3.put(property2, "value5");
    // When
    Properties state = props1;
    state = aggregator.apply(state, props2);
    state = aggregator.apply(state, props3);
    // Then
    assertEquals(props2, state);
}
Also used : ExampleTuple2BinaryOperator(uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator) TupleAdaptedBinaryOperator(uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator) KorypheBinaryOperator(uk.gov.gchq.koryphe.binaryoperator.KorypheBinaryOperator) BinaryOperator(java.util.function.BinaryOperator) ExampleTuple2BinaryOperator(uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)7 ExampleTuple2BinaryOperator (uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator)7 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)6 ExampleAggregateFunction (uk.gov.gchq.gaffer.function.ExampleAggregateFunction)6 StringConcat (uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat)2 BinaryOperator (java.util.function.BinaryOperator)1 Properties (uk.gov.gchq.gaffer.data.element.Properties)1 KorypheBinaryOperator (uk.gov.gchq.koryphe.binaryoperator.KorypheBinaryOperator)1 TupleAdaptedBinaryOperator (uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator)1