use of uk.gov.gchq.gaffer.operation.impl.join.Join in project Gaffer by gchq.
the class JoinIT method shouldRightKeyInnerJoin.
@Test
public void shouldRightKeyInnerJoin() throws OperationException {
// Given
final List<Element> expectedResults = innerJoinElements;
Join<Element> joinOp = new Join.Builder<Element>().input(inputElements).operation(rhsGetElementsOperation).joinType(JoinType.INNER).matchKey(MatchKey.RIGHT).matchMethod(new ElementMatch(TestPropertyNames.COUNT)).flatten(false).build();
// When
final Iterable<? extends MapTuple> results = graph.execute(joinOp, getUser());
// Then
assertKeysExist(expectedResults, results, MatchKey.RIGHT);
}
use of uk.gov.gchq.gaffer.operation.impl.join.Join in project Gaffer by gchq.
the class JoinIT method shouldLeftKeyFullJoin.
@Test
public void shouldLeftKeyFullJoin() throws OperationException {
// Given
final List<Element> expectedResults = new ArrayList<>(inputElements);
Join<Element> joinOp = new Join.Builder<Element>().input(inputElements).operation(rhsGetElementsOperation).joinType(JoinType.FULL).matchKey(MatchKey.LEFT).matchMethod(new ElementMatch(TestPropertyNames.COUNT)).flatten(false).build();
// When
final Iterable<? extends MapTuple> results = graph.execute(joinOp, getUser());
// Then
assertKeysExist(expectedResults, results, MatchKey.LEFT);
}
use of uk.gov.gchq.gaffer.operation.impl.join.Join in project Gaffer by gchq.
the class JoinIT method shouldRightKeyFullJoin.
@Test
public void shouldRightKeyFullJoin() throws OperationException {
// Given
final List<Element> expectedResults = innerJoinElements;
expectedResults.add(getJoinEntity(TestGroups.ENTITY_3, 8));
Join<Element> joinOp = new Join.Builder<Element>().input(inputElements).operation(rhsGetElementsOperation).joinType(JoinType.FULL).matchKey(MatchKey.RIGHT).matchMethod(new ElementMatch(TestPropertyNames.COUNT)).flatten(false).build();
// When
final Iterable<? extends MapTuple> results = graph.execute(joinOp, getUser());
// Then
assertKeysExist(expectedResults, results, MatchKey.RIGHT);
}
use of uk.gov.gchq.gaffer.operation.impl.join.Join 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);
}
use of uk.gov.gchq.gaffer.operation.impl.join.Join 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);
}
Aggregations