use of uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport in project Gaffer by gchq.
the class GetSetExportTest method builderShouldCreatePopulatedOperation.
@Test
@Override
public void builderShouldCreatePopulatedOperation() {
// When
final GetSetExport operation = new GetSetExport.Builder().key("key").jobId("jobId").start(0).end(5).build();
// Then
assertEquals("key", operation.getKey());
assertEquals("jobId", operation.getJobId());
assertEquals(0, operation.getStart());
assertEquals(5, (int) operation.getEnd());
}
use of uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport in project Gaffer by gchq.
the class LoadAndQuery7 method run.
public Iterable<Edge> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [graph] create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
// ---------------------------------------------------------
// [add] add the edges to the graph using an operation chain consisting of:
// generateElements - generating edges from the data (note these are directed edges)
// addElements - add the edges to the graph
// ---------------------------------------------------------
final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator7()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
// Create some starting seeds for the sub graph.
final Iterable<EntitySeed> seeds = Lists.newArrayList(new EntitySeed("1"));
// Create a view to return only edges that have a count more than 1
// Note we could have used a different view for each hop in order to
// specify the edges we wish to hop down or to attempt to prevent caching
// duplicate edges.
final View view = new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(1)).build()).build()).build();
// [extractor] Create a generator that will extract entity seeds
// This generator will extract just the destination vertices from edges
// and skip any entities.
// ---------------------------------------------------------
final EntitySeedExtractor destVerticesExtractor = new EntitySeedExtractor(new IsEdgeValidator(), new AlwaysValid<>(), true, IdentifierType.DESTINATION);
// ---------------------------------------------------------
// [get] Create a sub graph
// Start getting related edges with the given seeds.
// Then update the export with the results
// Between each hop we need to extract the destination vertices of the
// previous edges.
// Finally finish off by returning all the edges in the export.
// ---------------------------------------------------------
final OperationChain opChain = new OperationChain.Builder().first(new GetEdges.Builder<EntitySeed>().seeds(seeds).inOutType(IncludeIncomingOutgoingType.OUTGOING).view(view).build()).then(new ExportToSet()).then(new GenerateObjects<Edge, EntitySeed>(destVerticesExtractor)).then(new GetEdges.Builder<EntitySeed>().inOutType(IncludeIncomingOutgoingType.OUTGOING).view(view).build()).then(new ExportToSet()).then(new GetSetExport()).build();
final Iterable<Edge> subGraph = (Iterable<Edge>) graph.execute(opChain, user);
// ---------------------------------------------------------
log("\nSub graph:");
for (final Edge edge : subGraph) {
log("SUB_GRAPH", edge.toString());
}
return subGraph;
}
use of uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport in project Gaffer by gchq.
the class ExportIT method shouldExportResultsInSet.
@Test
public void shouldExportResultsInSet() throws OperationException, IOException {
// Given
final OperationChain<CloseableIterable<?>> exportOpChain = new Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(SOURCE_DIR_0)).build()).then(new ExportToSet()).then(new GenerateObjects.Builder<Edge, EntitySeed>().generator(new EntitySeedExtractor()).build()).then(new GetEdges<>()).then(new ExportToSet()).then(new GetSetExport()).build();
// When
final CloseableIterable<?> export = graph.execute(exportOpChain, getUser());
// Then
assertEquals(2, Lists.newArrayList(export).size());
}
use of uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport in project Gaffer by gchq.
the class GetSetExportTest method shouldSerialiseAndDeserialiseOperation.
@Test
@Override
public void shouldSerialiseAndDeserialiseOperation() throws SerialisationException {
// Given
final GetExport operation = new GetSetExport.Builder().key("key").jobId("jobId").start(0).end(5).build();
// When
byte[] json = serialiser.serialise(operation, true);
final GetSetExport deserialisedOp = serialiser.deserialise(json, GetSetExport.class);
// Then
assertEquals("key", deserialisedOp.getKey());
assertEquals("jobId", deserialisedOp.getJobId());
assertEquals(0, deserialisedOp.getStart());
assertEquals(5, (int) deserialisedOp.getEnd());
}
Aggregations