Search in sources :

Example 6 with ExtractProperty

use of uk.gov.gchq.gaffer.data.element.function.ExtractProperty in project Gaffer by gchq.

the class KeyFunctionMatchTest method shouldJsonSerialiseAndDeserialiseWithKeyFunctions.

@Test
public void shouldJsonSerialiseAndDeserialiseWithKeyFunctions() throws SerialisationException {
    // given
    KeyFunctionMatch match = new KeyFunctionMatch.Builder().firstKeyFunction(new FunctionComposite(Lists.newArrayList(new DivideBy(20), new FirstItem()))).secondKeyFunction(new ExtractProperty("count")).build();
    // when / then
    String expected = "{\n" + "  \"class\" : \"uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch\",\n" + "  \"firstKeyFunction\" : {\n" + "    \"class\" : \"uk.gov.gchq.koryphe.function.FunctionComposite\",\n" + "    \"functions\" : [ {\n" + "      \"class\" : \"uk.gov.gchq.koryphe.impl.function.DivideBy\",\n" + "      \"by\" : 20\n" + "    }, {\n" + "      \"class\" : \"uk.gov.gchq.koryphe.impl.function.FirstItem\"\n" + "    } ]\n" + "  },\n" + "  \"secondKeyFunction\" : {\n" + "    \"class\" : \"uk.gov.gchq.gaffer.data.element.function.ExtractProperty\",\n" + "    \"name\" : \"count\"\n" + "  }\n" + "}";
    assertEquals(expected, new String(JSONSerialiser.serialise(match, true)));
    assertEquals(match, JSONSerialiser.deserialise(expected, KeyFunctionMatch.class));
}
Also used : DivideBy(uk.gov.gchq.koryphe.impl.function.DivideBy) FirstItem(uk.gov.gchq.koryphe.impl.function.FirstItem) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) FunctionComposite(uk.gov.gchq.koryphe.function.FunctionComposite) Test(org.junit.jupiter.api.Test)

Example 7 with ExtractProperty

use of uk.gov.gchq.gaffer.data.element.function.ExtractProperty in project Gaffer by gchq.

the class GetWalksIT method shouldNotFilterWalksWhenNoPredicateSupplied.

@Test
public void shouldNotFilterWalksWhenNoPredicateSupplied() throws Exception {
    final Conditional conditional = new Conditional();
    conditional.setTransform(new OperationChain.Builder().first(new Map.Builder<>().first(new ExtractWalkEntities()).then(new IterableConcat()).build()).then(new ForEach.Builder<>().operation(new Map.Builder<>().first(new ExtractProperty(TestPropertyNames.PROP_1)).build()).build()).build());
    final Iterable<Walk> walks = executeGetWalksApplyingConditional(conditional);
    assertThat(getPaths(walks)).isEqualTo("AED,ABC");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) ExtractWalkEntities(uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntities) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) IterableConcat(uk.gov.gchq.koryphe.impl.function.IterableConcat) HashMap(java.util.HashMap) Map(uk.gov.gchq.gaffer.operation.impl.Map) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) Test(org.junit.Test)

Example 8 with ExtractProperty

use of uk.gov.gchq.gaffer.data.element.function.ExtractProperty in project Gaffer by gchq.

the class JoinIT method shouldRightSideFullJoinUsingKeyFunctionMatch.

@Test
public void shouldRightSideFullJoinUsingKeyFunctionMatch() throws OperationException {
    // Given
    final Map map = new Map.Builder<>().input(Lists.newArrayList(2L, 1L, 2L, 3L)).first(new Identity()).build();
    final ArrayList<Entity> input = Lists.newArrayList(getJoinEntity(TestGroups.ENTITY, 1), getJoinEntity(TestGroups.ENTITY_2, 2), getJoinEntity(TestGroups.ENTITY_2, 2), getJoinEntity(TestGroups.ENTITY_5, 5));
    final Join<Object> leftJoin = new Join.Builder<>().flatten(false).matchKey(MatchKey.RIGHT).joinType(JoinType.FULL).operation(map).matchMethod(new KeyFunctionMatch(new ToLong(), new ExtractProperty("count"))).input(input).build();
    // When
    final Iterable<? extends MapTuple> results = graph.execute(leftJoin, user);
    final List<java.util.Map> loadedResults = new ArrayList<>();
    results.forEach(e -> loadedResults.add(e.getValues()));
    // Then
    assertThat(loadedResults).hasSize(4);
    assertThat(loadedResults.get(0)).containsEntry(MatchKey.LEFT.name(), Lists.newArrayList(getJoinEntity(TestGroups.ENTITY_2, 2), getJoinEntity(TestGroups.ENTITY_2, 2))).containsEntry(MatchKey.RIGHT.name(), 2L);
    assertThat(loadedResults.get(1)).containsEntry(MatchKey.LEFT.name(), Lists.newArrayList(getJoinEntity(TestGroups.ENTITY, 1))).containsEntry(MatchKey.RIGHT.name(), 1L);
    assertThat(loadedResults.get(2)).containsEntry(MatchKey.LEFT.name(), Lists.newArrayList(getJoinEntity(TestGroups.ENTITY_2, 2), getJoinEntity(TestGroups.ENTITY_2, 2))).containsEntry(MatchKey.RIGHT.name(), 2L);
    assertThat(loadedResults.get(3)).containsEntry(MatchKey.LEFT.name(), Lists.newArrayList()).containsEntry(MatchKey.RIGHT.name(), 3L);
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) Entity(uk.gov.gchq.gaffer.data.element.Entity) ArrayList(java.util.ArrayList) Join(uk.gov.gchq.gaffer.operation.impl.join.Join) KeyFunctionMatch(uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) Identity(uk.gov.gchq.koryphe.impl.function.Identity) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.Test)

Example 9 with ExtractProperty

use of uk.gov.gchq.gaffer.data.element.function.ExtractProperty in project Gaffer by gchq.

the class JoinIT method shouldRightSideInnerJoinUsingKeyFunctionMatch.

@Test
public void shouldRightSideInnerJoinUsingKeyFunctionMatch() throws OperationException {
    // Given
    final Map map = new Map.Builder<>().input(Lists.newArrayList(4L)).first(new Identity()).build();
    final ArrayList<Entity> input = Lists.newArrayList(getJoinEntity(TestGroups.ENTITY, 4), getJoinEntity(TestGroups.ENTITY_2, 4), getJoinEntity(TestGroups.ENTITY_3, 4));
    final Join<Object> rightJoin = new Join.Builder<>().flatten(true).matchKey(MatchKey.RIGHT).joinType(JoinType.INNER).operation(map).matchMethod(new KeyFunctionMatch(new Identity(), new ExtractProperty("count"))).input(input).build();
    // When
    final Iterable<? extends MapTuple> rightResults = graph.execute(rightJoin, user);
    final List<java.util.Map> loadedResults = new ArrayList<>();
    rightResults.forEach(e -> loadedResults.add(e.getValues()));
    // Then
    assertThat(loadedResults).hasSize(3);
    assertThat(loadedResults.get(0)).containsEntry(MatchKey.LEFT.name(), getJoinEntity(TestGroups.ENTITY, 4)).containsEntry(MatchKey.RIGHT.name(), 4L);
    assertThat(loadedResults.get(1)).containsEntry(MatchKey.LEFT.name(), getJoinEntity(TestGroups.ENTITY_2, 4)).containsEntry(MatchKey.RIGHT.name(), 4L);
    assertThat(loadedResults.get(2)).containsEntry(MatchKey.LEFT.name(), getJoinEntity(TestGroups.ENTITY_3, 4)).containsEntry(MatchKey.RIGHT.name(), 4L);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) ArrayList(java.util.ArrayList) Join(uk.gov.gchq.gaffer.operation.impl.join.Join) KeyFunctionMatch(uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) Identity(uk.gov.gchq.koryphe.impl.function.Identity) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.Test)

Example 10 with ExtractProperty

use of uk.gov.gchq.gaffer.data.element.function.ExtractProperty in project Gaffer by gchq.

the class GetWalksIT method getWalksThatPassPredicateTest.

private Iterable<Walk> getWalksThatPassPredicateTest(final Predicate predicate) throws Exception {
    final Conditional conditional = new Conditional();
    conditional.setTransform(new OperationChain.Builder().first(new Map.Builder<>().first(new ExtractWalkEntities()).then(new IterableConcat()).build()).then(new ForEach.Builder<>().operation(new Map.Builder<>().first(new ExtractProperty(TestPropertyNames.PROP_1)).build()).build()).build());
    conditional.setPredicate(predicate);
    return executeGetWalksApplyingConditional(conditional);
}
Also used : ExtractWalkEntities(uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntities) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) IterableConcat(uk.gov.gchq.koryphe.impl.function.IterableConcat) HashMap(java.util.HashMap) Map(uk.gov.gchq.gaffer.operation.impl.Map) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach)

Aggregations

ExtractProperty (uk.gov.gchq.gaffer.data.element.function.ExtractProperty)10 Entity (uk.gov.gchq.gaffer.data.element.Entity)6 Map (uk.gov.gchq.gaffer.operation.impl.Map)5 Test (org.junit.Test)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 Join (uk.gov.gchq.gaffer.operation.impl.join.Join)3 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)3 KeyFunctionMatch (uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch)3 Identity (uk.gov.gchq.koryphe.impl.function.Identity)3 ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)3 HashMap (java.util.HashMap)2 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 ExtractWalkEntities (uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntities)2 ForEach (uk.gov.gchq.gaffer.operation.impl.ForEach)2 Builder (uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder)2 FunctionComposite (uk.gov.gchq.koryphe.function.FunctionComposite)2 IterableConcat (uk.gov.gchq.koryphe.impl.function.IterableConcat)2 Predicate (java.util.function.Predicate)1 Element (uk.gov.gchq.gaffer.data.element.Element)1