Search in sources :

Example 6 with ExampleTuple2BinaryOperator

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

the class SchemaElementDefinitionTest method shouldReturnQueryAggregatorWithMultiPropertyAggregatorWithSingleGroupBy.

@Test
public void shouldReturnQueryAggregatorWithMultiPropertyAggregatorWithSingleGroupBy() {
    // 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").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
    // As the groupBy property - property1 is aggregated alongside property2, this is still required in the aggregator function.
    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 7 with ExampleTuple2BinaryOperator

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

the class SchemaElementDefinitionTest method shouldReturnIngestAggregatorWithMultiPropertyAggregator.

@Test
public void shouldReturnIngestAggregatorWithMultiPropertyAggregator() {
    // 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", "timestamp").execute(new ExampleTuple2BinaryOperator()).build()).build();
    setupSchema(elementDef);
    // When
    final ElementAggregator aggregator = elementDef.getIngestAggregator();
    // Then
    int i = 0;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property3", "timestamp" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "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++;
    assertEquals(i, aggregator.getComponents().size());
    // Check the aggregator is locked.
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> aggregator.getComponents().add(null)).isNotNull();
    // check the aggregator is cached
    assertSame(aggregator, elementDef.getIngestAggregator());
}
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)

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