Search in sources :

Example 1 with JoinFunction

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

the class JoinHandler method doOperation.

@Override
public Iterable<? extends MapTuple> doOperation(final Join<I> operation, final Context context, final Store store) throws OperationException {
    final int limit = operation.getCollectionLimit() != null ? operation.getCollectionLimit() : 100000;
    if (null == operation.getJoinType()) {
        throw new OperationException("A join type must be specified");
    }
    if (null == operation.getMatchMethod()) {
        throw new OperationException("A match method must be supplied");
    }
    if (null == operation.getInput()) {
        operation.setInput(new ArrayList<>());
    }
    MatchKey matchKey = operation.getMatchKey();
    if (null == matchKey) {
        if (!operation.getJoinType().equals(JoinType.INNER)) {
            throw new OperationException("You must specify an Iterable side to match on");
        }
        // setting match key to avoid swapping inputs
        matchKey = MatchKey.LEFT;
    }
    JoinFunction joinFunction = operation.getJoinType().createInstance();
    updateOperationInput(operation.getOperation(), null);
    Iterable<I> rightIterable = (Iterable<I>) getResultsOrNull(operation.getOperation(), context, store);
    final Iterable limitedLeftIterable;
    final Iterable limitedRightIterable;
    try {
        limitedLeftIterable = new LimitedCloseableIterable(operation.getInput(), 0, limit, false);
        limitedRightIterable = new LimitedCloseableIterable(rightIterable, 0, limit, false);
        return joinFunction.join(limitedLeftIterable, limitedRightIterable, operation.getMatchMethod(), matchKey, operation.isFlatten());
    } catch (final LimitExceededException e) {
        throw new OperationException("Join exceeded the collectionLimit, a solution is to increasing collectionLimit value in the join operation.", e);
    }
}
Also used : LimitedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.LimitedCloseableIterable) LimitedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.LimitedCloseableIterable) MatchKey(uk.gov.gchq.gaffer.operation.impl.join.match.MatchKey) JoinFunction(uk.gov.gchq.gaffer.operation.impl.join.methods.JoinFunction) LimitExceededException(uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

LimitExceededException (uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException)1 LimitedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.LimitedCloseableIterable)1 OperationException (uk.gov.gchq.gaffer.operation.OperationException)1 MatchKey (uk.gov.gchq.gaffer.operation.impl.join.match.MatchKey)1 JoinFunction (uk.gov.gchq.gaffer.operation.impl.join.methods.JoinFunction)1