Search in sources :

Example 1 with Join

use of uk.gov.gchq.gaffer.operation.impl.join.Join in project Gaffer by gchq.

the class JoinTest method shouldJsonSerialiseAndDeserialise.

@Test
@Override
public void shouldJsonSerialiseAndDeserialise() {
    // Given
    final Join op = new Join.Builder<>().input(new Entity.Builder().build(), new Entity.Builder().build()).operation(new GetAllElements.Builder().build()).matchMethod(new TestMatchImpl()).matchKey(MatchKey.LEFT).joinType(JoinType.INNER).flatten(false).collectionLimit(10).build();
    // When
    final byte[] json = toJson(op);
    final String jsonString = new String(json);
    final Join deserialisedObj = fromJson(json);
    // Then
    assertSame(deserialisedObj.getClass(), op.getClass());
    assertEquals(2, StringUtils.countMatches(jsonString, "\"class\" : \"uk.gov.gchq.gaffer.data.element.Entity\""), "Should be the same amount of classes as inputs given after deserialisation");
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Join(uk.gov.gchq.gaffer.operation.impl.join.Join) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 2 with Join

use of uk.gov.gchq.gaffer.operation.impl.join.Join in project Gaffer by gchq.

the class JoinTest method shouldShallowCloneOperation.

@Test
@Override
public void shouldShallowCloneOperation() {
    // Given
    final Join op = new Join.Builder<>().input(Arrays.asList(1, 2, 3)).operation(new GetAllElements.Builder().build()).matchMethod(new TestMatchImpl()).matchKey(MatchKey.LEFT).joinType(JoinType.INNER).flatten(false).collectionLimit(10).build();
    // When
    final Join clone = op.shallowClone();
    assertNotEquals(op, clone);
    assertEquals(clone.getInput(), op.getInput());
    assertEquals(clone.getOperation(), op.getOperation());
    assertEquals(clone.getJoinType(), op.getJoinType());
    assertEquals(clone.getMatchMethod(), op.getMatchMethod());
}
Also used : Join(uk.gov.gchq.gaffer.operation.impl.join.Join) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 3 with Join

use of uk.gov.gchq.gaffer.operation.impl.join.Join in project Gaffer by gchq.

the class JoinHandlerTest method shouldSetInputToNewArrayListWhenNull.

@Test
public void shouldSetInputToNewArrayListWhenNull() throws OperationException {
    // Given
    final JoinHandler handler = new JoinHandler();
    final Join joinOp = new Join.Builder<>().joinType(JoinType.FULL).matchMethod(new ElementMatch()).matchKey(MatchKey.LEFT).build();
    // When
    handler.doOperation(joinOp, context, store);
    // Then
    assertTrue(joinOp.getInput().equals(new ArrayList<>()));
}
Also used : ElementMatch(uk.gov.gchq.gaffer.store.operation.handler.join.match.ElementMatch) ArrayList(java.util.ArrayList) Join(uk.gov.gchq.gaffer.operation.impl.join.Join) JoinHandler(uk.gov.gchq.gaffer.store.operation.handler.join.JoinHandler) Test(org.junit.jupiter.api.Test)

Example 4 with Join

use of uk.gov.gchq.gaffer.operation.impl.join.Join 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 5 with Join

use of uk.gov.gchq.gaffer.operation.impl.join.Join in project Gaffer by gchq.

the class JoinTest method builderShouldCreatePopulatedOperation.

@Test
@Override
public void builderShouldCreatePopulatedOperation() {
    // Given
    final Join op = new Join.Builder<>().input(Arrays.asList(1, 2, 3)).operation(new GetAllElements.Builder().build()).matchMethod(new TestMatchImpl()).matchKey(MatchKey.LEFT).joinType(JoinType.INNER).flatten(false).collectionLimit(10).build();
    // Then
    assertEquals(Arrays.asList(1, 2, 3), op.getInput());
    assertTrue(op.getOperation() instanceof GetAllElements);
    assertEquals(JoinType.INNER, op.getJoinType());
    assertTrue(op.getMatchMethod() instanceof Match);
    assertEquals(MatchKey.LEFT, op.getMatchKey());
    assertTrue(op.isFlatten() instanceof Boolean);
    assertTrue(op.getCollectionLimit().equals(10));
}
Also used : GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Join(uk.gov.gchq.gaffer.operation.impl.join.Join) Match(uk.gov.gchq.gaffer.operation.impl.join.match.Match) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Join (uk.gov.gchq.gaffer.operation.impl.join.Join)10 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)4 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 ElementMatch (uk.gov.gchq.gaffer.store.operation.handler.join.match.ElementMatch)4 Element (uk.gov.gchq.gaffer.data.element.Element)3 ExtractProperty (uk.gov.gchq.gaffer.data.element.function.ExtractProperty)3 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)3 Map (uk.gov.gchq.gaffer.operation.impl.Map)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)2 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)1 Match (uk.gov.gchq.gaffer.operation.impl.join.match.Match)1 JoinHandler (uk.gov.gchq.gaffer.store.operation.handler.join.JoinHandler)1