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