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