Search in sources :

Example 1 with KeyFunctionMatch

use of uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch in project Gaffer by gchq.

the class JoinHandlerTest method shouldThrowExceptionWhenInputIsMoreThanLimit.

@Test
public void shouldThrowExceptionWhenInputIsMoreThanLimit() {
    // Given
    final JoinHandler handler = new JoinHandler();
    final List<Integer> inputList = Arrays.asList(1, 2, 3);
    final Join<Integer> joinOp = new Join.Builder<Integer>().input(inputList).joinType(JoinType.FULL).matchKey(MatchKey.LEFT).matchMethod(new KeyFunctionMatch()).collectionLimit(1).build();
    // When / Then
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(joinOp, context, store)).withMessageContaining("exceeded");
}
Also used : JoinHandler(uk.gov.gchq.gaffer.store.operation.handler.join.JoinHandler) KeyFunctionMatch(uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch) Test(org.junit.jupiter.api.Test)

Example 2 with KeyFunctionMatch

use of uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch 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)

Example 3 with KeyFunctionMatch

use of uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch 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 4 with KeyFunctionMatch

use of uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch 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)

Aggregations

KeyFunctionMatch (uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 ExtractProperty (uk.gov.gchq.gaffer.data.element.function.ExtractProperty)3 Map (uk.gov.gchq.gaffer.operation.impl.Map)3 Join (uk.gov.gchq.gaffer.operation.impl.join.Join)3 Identity (uk.gov.gchq.koryphe.impl.function.Identity)3 ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)2 Test (org.junit.jupiter.api.Test)1 JoinHandler (uk.gov.gchq.gaffer.store.operation.handler.join.JoinHandler)1