Search in sources :

Example 1 with ExtractProperty

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

the class ExtractPropertyExample method extractPropertyFromElement.

public void extractPropertyFromElement() {
    // ---------------------------------------------------------
    final ExtractProperty function = new ExtractProperty("prop1");
    // ---------------------------------------------------------
    runExample(function, "If present, the function will extract the value of the specified property, otherwise returning null.", new Edge.Builder().group("edge").source("src").dest("dest").property("prop1", 3).property("prop2", "test").build(), new Entity.Builder().group("entity").vertex("vertex").property("prop1", 12).property("prop2", 2).property("prop3", "test").build(), new Edge.Builder().build());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 2 with ExtractProperty

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

the class KeyFunctionMatchTest method shouldMatchElementsOfDifferentGroupsBasedOnKeyFunctions.

@Test
public void shouldMatchElementsOfDifferentGroupsBasedOnKeyFunctions() {
    // given
    Entity testItem = new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test").property(PROP_1, 2L).build();
    List<Entity> testList = Lists.newArrayList(new Entity.Builder().group(TEST_ENTITY_GROUP_2).vertex("test2").property(PROP_2, 2).build(), new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test3").property(PROP_1, 3L).build(), new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test1").property(PROP_1, 4L).build(), new Entity.Builder().group(TEST_ENTITY_GROUP_2).vertex("test3").property(PROP_2, 2).build());
    // when
    KeyFunctionMatch match = new KeyFunctionMatch.Builder().firstKeyFunction(new ExtractProperty(PROP_1)).secondKeyFunction(new FunctionComposite(Lists.newArrayList(new ExtractProperty(PROP_2), new ToLong()))).build();
    match.init(testList);
    // then
    ArrayList<Entity> expected = Lists.newArrayList(new Entity.Builder().group(TEST_ENTITY_GROUP_2).vertex("test2").property(PROP_2, 2).build(), new Entity.Builder().group(TEST_ENTITY_GROUP_2).vertex("test3").property(PROP_2, 2).build());
    assertEquals(expected, match.matching(testItem));
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) Entity(uk.gov.gchq.gaffer.data.element.Entity) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) FunctionComposite(uk.gov.gchq.koryphe.function.FunctionComposite) Test(org.junit.jupiter.api.Test)

Example 3 with ExtractProperty

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

the class KeyFunctionMatchTest method shouldMatchElementsOfTheSameGroupBasedOnKeyFunctions.

@Test
public void shouldMatchElementsOfTheSameGroupBasedOnKeyFunctions() {
    // given
    Entity testItem = new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test").property(PROP_1, 3L).build();
    List<Entity> testList = Lists.newArrayList(new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test2").property(PROP_1, 2L).build(), new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test3").property(PROP_1, 3L).build(), new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test1").property(PROP_1, 4L).build(), new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test3").property(PROP_1, 3L).build());
    // when
    KeyFunctionMatch match = new KeyFunctionMatch.Builder().firstKeyFunction(new ExtractProperty(PROP_1)).secondKeyFunction(new ExtractProperty(PROP_1)).build();
    match.init(testList);
    // then
    ArrayList<Entity> expected = Lists.newArrayList(new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test3").property(PROP_1, 3L).build(), new Entity.Builder().group(TEST_ENTITY_GROUP).vertex("test3").property(PROP_1, 3L).build());
    assertEquals(expected, match.matching(testItem));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) Test(org.junit.jupiter.api.Test)

Example 4 with ExtractProperty

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

the class WhileHandlerTest method shouldFailPredicateTestAndNotExecuteDelegateOperation.

@Test
public void shouldFailPredicateTestAndNotExecuteDelegateOperation() throws OperationException {
    // Given
    final Edge input = new Edge.Builder().group("testEdge").source("src").dest("dest").directed(true).property("count", 3).build();
    final Map<Element, Object> transform = new Map.Builder<Element>().first(new ExtractProperty("count")).build();
    final Predicate predicate = new IsMoreThan(5);
    final Conditional conditional = new Conditional(predicate, transform);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final GetElements getElements = mock(GetElements.class);
    final While operation = new While.Builder<>().input(input).maxRepeats(1).conditional(conditional).operation(getElements).build();
    final WhileHandler handler = new WhileHandler();
    // When
    handler.doOperation(operation, context, store);
    // Then
    verify(store, never()).execute((Output) getElements, context);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) While(uk.gov.gchq.gaffer.operation.impl.While) Predicate(java.util.function.Predicate) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 5 with ExtractProperty

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

the class JoinIT method shouldLeftSideOuterJoinUsingKeyFunctionMatch.

@Test
public void shouldLeftSideOuterJoinUsingKeyFunctionMatch() throws OperationException {
    // Given
    final Map map = new Map.Builder<>().input(Lists.newArrayList(4L, 1L, 2L)).first(new Identity()).build();
    final ArrayList<Entity> input = Lists.newArrayList(getJoinEntity(TestGroups.ENTITY, 4), getJoinEntity(TestGroups.ENTITY_2, 4), getJoinEntity(TestGroups.ENTITY_3, 2), getJoinEntity(TestGroups.ENTITY_4, 5), getJoinEntity(TestGroups.ENTITY_4, 6), getJoinEntity(TestGroups.ENTITY_5, 5));
    final Join<Object> leftJoin = new Join.Builder<>().flatten(true).matchKey(MatchKey.LEFT).joinType(JoinType.OUTER).operation(map).matchMethod(new KeyFunctionMatch(new ExtractProperty("count"), new ToLong())).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(3);
    assertThat(loadedResults.get(0)).containsEntry(MatchKey.LEFT.name(), getJoinEntity(TestGroups.ENTITY_4, 5)).containsEntry(MatchKey.RIGHT.name(), null);
    assertThat(loadedResults.get(1)).containsEntry(MatchKey.LEFT.name(), getJoinEntity(TestGroups.ENTITY_4, 6)).containsEntry(MatchKey.RIGHT.name(), null);
    assertThat(loadedResults.get(2)).containsEntry(MatchKey.LEFT.name(), getJoinEntity(TestGroups.ENTITY_5, 5)).containsEntry(MatchKey.RIGHT.name(), null);
}
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)

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