Search in sources :

Example 1 with Output

use of uk.gov.gchq.gaffer.operation.io.Output in project Gaffer by gchq.

the class GetElementsInRangesHandlerTest method shouldSummarise.

private void shouldSummarise(final AccumuloStore store) throws OperationException {
    // Given - get everything between 0 and 1 (Note we are using strings and string serialisers, with this ordering 0999 is before 1)
    final Set<Pair<ElementId, ElementId>> simpleEntityRanges = new HashSet<>();
    simpleEntityRanges.add(new Pair<>(new EntitySeed("0"), new EntitySeed("1")));
    final View view = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
    final Output operation = createOperation(simpleEntityRanges, view, IncludeIncomingOutgoingType.EITHER, DirectedType.EITHER);
    // When
    List<Element> results = executeOperation(operation, store);
    // Then
    ElementUtil.assertElementEquals(createSummarisedElements(NUM_ENTRIES), results);
    // Given - this should get everything between 0 and 0799 (again being string ordering 0800 is more than 08)
    simpleEntityRanges.clear();
    simpleEntityRanges.add(new Pair<>(new EntitySeed("0"), new EntitySeed("08")));
    // When
    results = executeOperation(operation, store);
    // Then
    ElementUtil.assertElementEquals(createSummarisedElements(800), results);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Output(uk.gov.gchq.gaffer.operation.io.Output) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) HashSet(java.util.HashSet)

Example 2 with Output

use of uk.gov.gchq.gaffer.operation.io.Output in project Gaffer by gchq.

the class FederatedAddGraphHandlerParent method addGenericHandler.

protected void addGenericHandler(final FederatedStore store, final Graph graph) {
    for (final Class<? extends Operation> supportedOperation : graph.getSupportedOperations()) {
        // some operations are not suitable for FederatedOperationGenericOutputHandler
        if (!store.isSupported(supportedOperation)) {
            if (Output.class.isAssignableFrom(supportedOperation)) {
                Class<? extends Output> supportedOutputOperation = (Class<? extends Output>) supportedOperation;
                Class outputClass;
                try {
                    outputClass = supportedOutputOperation.newInstance().getOutputClass();
                } catch (final InstantiationException | IllegalAccessException e) {
                    LOGGER.warn("Exception occurred while trying to create a newInstance of operation: " + supportedOperation, e);
                    continue;
                }
                if (CloseableIterable.class.equals(outputClass)) {
                    store.addOperationHandler((Class) supportedOutputOperation, new FederatedOperationIterableHandler());
                } else {
                    LOGGER.warn("No generic default handler can be used for an Output operation that does not return CloseableIterable. operation: " + supportedOutputOperation);
                }
            } else {
                store.addOperationHandler(supportedOperation, new FederatedOperationHandler());
            }
        }
    }
}
Also used : Output(uk.gov.gchq.gaffer.operation.io.Output) FederatedOperationIterableHandler(uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedOperationIterableHandler)

Example 3 with Output

use of uk.gov.gchq.gaffer.operation.io.Output in project Gaffer by gchq.

the class OperationChainValidator method validateInputOutputTypes.

protected Class<? extends Output> validateInputOutputTypes(final Operation operation, final ValidationResult validationResult, final Store store, final Class<? extends Output> input) {
    Class<? extends Output> output = input;
    if (null == input) {
        if (operation instanceof Output) {
            output = ((Output) operation).getClass();
        }
    } else {
        final Operation firstOp = getFirstOperation(operation);
        if (firstOp instanceof Input) {
            final Class<?> outputType = OperationUtil.getOutputType(input);
            final Class<?> inputType = OperationUtil.getInputType(((Input) firstOp));
            validationResult.add(OperationUtil.isValid(outputType, inputType));
        } else {
            validationResult.addError("Invalid combination of operations: " + input.getName() + " -> " + firstOp.getClass().getName() + ". " + input.getClass().getSimpleName() + " has an output but " + firstOp.getClass().getSimpleName() + " does not take an input.");
        }
        if (operation instanceof Output) {
            output = ((Output) operation).getClass();
        } else {
            output = null;
        }
    }
    return output;
}
Also used : Input(uk.gov.gchq.gaffer.operation.io.Input) Output(uk.gov.gchq.gaffer.operation.io.Output) Operation(uk.gov.gchq.gaffer.operation.Operation)

Example 4 with Output

use of uk.gov.gchq.gaffer.operation.io.Output in project Gaffer by gchq.

the class OperationControllerTest method shouldCorrectlyChunkIterables.

@Test
public void shouldCorrectlyChunkIterables() throws IOException, OperationException {
    // Given
    when(userFactory.createContext()).thenReturn(new Context(new User()));
    when(store.execute(any(Output.class), any(Context.class))).thenReturn(Arrays.asList(1, 2, 3));
    // When
    ResponseEntity<StreamingResponseBody> response = operationController.executeChunked(new GetAllElements());
    OutputStream output = new ByteArrayOutputStream();
    response.getBody().writeTo(output);
    // Then
    assertEquals("1\r\n2\r\n3\r\n", output.toString());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Output(uk.gov.gchq.gaffer.operation.io.Output) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 5 with Output

use of uk.gov.gchq.gaffer.operation.io.Output in project Gaffer by gchq.

the class GetWalksHandler method executeWhileOperation.

private List<?> executeWhileOperation(final OperationChain<Iterable<Element>> operation, final List<?> seeds, final Integer resultLimit, final Context context, final Store store, final int hops, final AdjacencyMaps adjacencyMaps, final EntityMaps entityMaps) throws OperationException {
    List<?> resultSeeds = seeds;
    final While whileOp = (While) operation.getOperations().get(0);
    if (null != whileOp.getOperation()) {
        validateWhileOperation(whileOp);
        final OperationHandler opHandler = store.getOperationHandler(While.class);
        if (null == opHandler) {
            throw new UnsupportedOperationException("While operations are not supported by this store");
        }
        if (!(opHandler instanceof WhileHandler)) {
            throw new UnsupportedOperationException("To use While operations within GetWalks, the While handler must be a " + WhileHandler.class.getName());
        }
        final WhileHandler whileHandler = (WhileHandler) opHandler;
        whileHandler.validateMaxRepeats(whileOp);
        // Change the transform to unwrap entity ids first.
        if (null != whileOp.getConditional() && null != whileOp.getConditional().getTransform()) {
            whileOp.getConditional().setTransform(new OperationChain<>(new Map.Builder<>().first(new IterableFunction.Builder<>().first(new UnwrapEntityId()).build()).build(), whileOp.getConditional().getTransform()));
        }
        for (int repeatCount = 0; repeatCount < whileOp.getMaxRepeats(); repeatCount++) {
            final While whileOpClone = whileOp.shallowClone();
            if (!whileHandler.isSatisfied(resultSeeds, whileOpClone, context, store)) {
                break;
            }
            resultSeeds = executeOperation((Output) whileOpClone.getOperation(), resultSeeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps);
        }
    }
    return resultSeeds;
}
Also used : Output(uk.gov.gchq.gaffer.operation.io.Output) While(uk.gov.gchq.gaffer.operation.impl.While) UnwrapEntityId(uk.gov.gchq.gaffer.data.element.function.UnwrapEntityId)

Aggregations

Output (uk.gov.gchq.gaffer.operation.io.Output)10 Element (uk.gov.gchq.gaffer.data.element.Element)6 HashSet (java.util.HashSet)5 Pair (uk.gov.gchq.gaffer.commonutil.pair.Pair)5 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)5 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)4 Strings (com.google.common.base.Strings)1 Sets (com.google.common.collect.Sets)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects.isNull (java.util.Objects.isNull)1 Objects.nonNull (java.util.Objects.nonNull)1 Random (java.util.Random)1