Search in sources :

Example 1 with ExportToSet

use of uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet in project Gaffer by gchq.

the class ExportToSetTest method builderShouldCreatePopulatedOperation.

@Test
@Override
public void builderShouldCreatePopulatedOperation() {
    // When
    final ExportToSet op = new ExportToSet.Builder().key("key").build();
    // Then
    assertEquals("key", op.getKey());
}
Also used : ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.Test)

Example 2 with ExportToSet

use of uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet 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;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) GetSetExport(uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport) IsEdgeValidator(uk.gov.gchq.gaffer.data.IsEdgeValidator) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) DataGenerator7(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator7) Graph(uk.gov.gchq.gaffer.graph.Graph) EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 3 with ExportToSet

use of uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet 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());
}
Also used : ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetSetExport(uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 4 with ExportToSet

use of uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet in project Gaffer by gchq.

the class ExportToSetTest method shouldSerialiseAndDeserialiseOperation.

@Test
@Override
public void shouldSerialiseAndDeserialiseOperation() throws SerialisationException {
    // Given
    final String key = "key";
    final ExportToSet op = new ExportToSet.Builder().key(key).build();
    // When
    byte[] json = serialiser.serialise(op, true);
    final ExportToSet deserialisedOp = serialiser.deserialise(json, ExportToSet.class);
    // Then
    assertEquals(key, deserialisedOp.getKey());
}
Also used : ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.Test)

Aggregations

ExportToSet (uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet)4 Test (org.junit.Test)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 EntitySeedExtractor (uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor)2 GetSetExport (uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport)2 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)2 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 IsEdgeValidator (uk.gov.gchq.gaffer.data.IsEdgeValidator)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 DataGenerator7 (uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator7)1 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)1 User (uk.gov.gchq.gaffer.user.User)1