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());
}
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));
}
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));
}
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);
}
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);
}
Aggregations