Search in sources :

Example 26 with OperationChain

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

the class GeneratorsIT method shouldConvertToDomainObjects.

@Test
public void shouldConvertToDomainObjects() throws OperationException, UnsupportedEncodingException {
    // Given
    final OperationChain<CloseableIterable<DomainObject>> opChain = new OperationChain.Builder().first(new GetElements.Builder<>().addSeed(new EntitySeed(SOURCE_1)).build()).then(new GenerateObjects.Builder<Element, DomainObject>().generator(new BasicGenerator()).outputType(new TypeReference<CloseableIterable<DomainObject>>() {
    }).build()).build();
    // When
    final List<DomainObject> results = Lists.newArrayList(graph.execute(opChain, getUser()));
    final EntityDomainObject entityDomainObject = new EntityDomainObject(SOURCE_1, "3", null);
    final EdgeDomainObject edgeDomainObject = new EdgeDomainObject(SOURCE_1, DEST_1, false, 1, 1L);
    // Then
    assertNotNull(results);
    assertEquals(2, results.size());
    assertThat(results, IsCollectionContaining.hasItems(entityDomainObject, edgeDomainObject));
}
Also used : BasicGenerator(uk.gov.gchq.gaffer.integration.generators.BasicGenerator) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) EntityDomainObject(uk.gov.gchq.gaffer.integration.domain.EntityDomainObject) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) EdgeDomainObject(uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) EdgeDomainObject(uk.gov.gchq.gaffer.integration.domain.EdgeDomainObject) DomainObject(uk.gov.gchq.gaffer.integration.domain.DomainObject) EntityDomainObject(uk.gov.gchq.gaffer.integration.domain.EntityDomainObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 27 with OperationChain

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

the class LoadAndQuery8 method run.

public Iterable<Edge> run() throws OperationException {
    // [user] Create a user who can see public and private data
    // ---------------------------------------------------------
    final User user = new User.Builder().userId("user").dataAuths("public", "private").build();
    // ---------------------------------------------------------
    // [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
    // ---------------------------------------------------------
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator8()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    // [get] Get all edges
    // ---------------------------------------------------------
    final GetAllEdges allEdgesOperation = new GetAllEdges();
    final Iterable<Edge> edges = graph.execute(allEdgesOperation, user);
    // ---------------------------------------------------------
    log("\nAll edges in daily time buckets:");
    for (final Edge edge : edges) {
        log("GET_ALL_EDGES_RESULT", edge.toString());
    }
    // [get all edges summarised] Get all edges summarised (merge all time windows together)
    // This is achieved by overriding the 'groupBy' start and end time properties.
    // ---------------------------------------------------------
    final GetAllEdges edgesSummarisedOperation = new GetAllEdges.Builder().view(new View.Builder().edge("data", new ViewElementDefinition.Builder().groupBy().build()).build()).build();
    final Iterable<Edge> edgesSummarised = graph.execute(edgesSummarisedOperation, user);
    // ---------------------------------------------------------
    log("\nAll edges summarised:");
    for (final Edge edge : edgesSummarised) {
        log("GET_ALL_EDGES_SUMMARISED_RESULT", edge.toString());
    }
    // [get all edges summarised in time window] Get all edges summarised over a provided 2 day time period
    // This is achieved by overriding the 'groupBy' start and end time properties
    // and providing a filter.
    // ---------------------------------------------------------
    final GetAllEdges edgesSummarisedInTimeWindowOperation = new GetAllEdges.Builder().view(new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate").execute(new IsMoreThan(JAN_01_16, true)).select("endDate").execute(new IsLessThan(JAN_02_16, true)).build()).groupBy().build()).build()).build();
    final Iterable<Edge> edgesSummarisedInTimeWindow = graph.execute(edgesSummarisedInTimeWindowOperation, user);
    // ---------------------------------------------------------
    log("\nEdges in 2 day time window:");
    for (final Edge edge : edgesSummarisedInTimeWindow) {
        log("GET_ALL_EDGES_SUMMARISED_IN_TIME_WINDOW_RESULT", edge.toString());
    }
    // Repeat with a public user and you will see the private edges are not part of the summarised edges
    final User publicUser = new User.Builder().userId("public user").dataAuths("public").build();
    final Iterable<Edge> publicEdgesSummarisedInTimeWindow = graph.execute(edgesSummarisedInTimeWindowOperation, publicUser);
    log("\nPublic edges in 2 day time window:");
    for (final Edge edge : publicEdgesSummarisedInTimeWindow) {
        log("GET_PUBLIC_EDGES_SUMMARISED_IN_TIME_WINDOW_RESULT", edge.toString());
    }
    return publicEdgesSummarisedInTimeWindow;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) DataGenerator8(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator8) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 28 with OperationChain

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

the class CoreOperationChainOptimiserTest method shouldNotAddLimitOperationForGetOperationsWithoutLimit.

@Test
public void shouldNotAddLimitOperationForGetOperationsWithoutLimit() throws Exception {
    // Given
    final Store store = mock(Store.class);
    final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
    final GetIterableOperation getOperation = mock(GetIterableOperation.class);
    final OperationChain<Integer> opChain = new OperationChain<>(getOperation);
    final Integer resultLimit = null;
    given(getOperation.getResultLimit()).willReturn(resultLimit);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(1, optimisedOpChain.getOperations().size());
    assertSame(getOperation, optimisedOpChain.getOperations().get(0));
}
Also used : GetIterableOperation(uk.gov.gchq.gaffer.operation.GetIterableOperation) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 29 with OperationChain

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

the class CoreOperationChainOptimiserTest method shouldAddDeduplicateOperationForGetOperationsWithDuplicateFlag.

@Test
public void shouldAddDeduplicateOperationForGetOperationsWithDuplicateFlag() throws Exception {
    // Given
    final Store store = mock(Store.class);
    final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
    final GetIterableOperation getOperation = mock(GetIterableOperation.class);
    final OperationChain<Integer> opChain = new OperationChain<>(getOperation);
    given(getOperation.getResultLimit()).willReturn(null);
    given(getOperation.isDeduplicate()).willReturn(true);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(2, optimisedOpChain.getOperations().size());
    assertSame(getOperation, optimisedOpChain.getOperations().get(0));
    assertTrue(optimisedOpChain.getOperations().get(1) instanceof Deduplicate);
}
Also used : Deduplicate(uk.gov.gchq.gaffer.operation.impl.Deduplicate) GetIterableOperation(uk.gov.gchq.gaffer.operation.GetIterableOperation) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 30 with OperationChain

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

the class CoreOperationChainOptimiserTest method shouldAddLimitOperationForGetOperationsWithLimit.

@Test
public void shouldAddLimitOperationForGetOperationsWithLimit() throws Exception {
    // Given
    final Store store = mock(Store.class);
    final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
    final GetIterableOperation getOperation = mock(GetIterableOperation.class);
    final OperationChain<Integer> opChain = new OperationChain<>(getOperation);
    final int resultLimit = 5;
    given(getOperation.getResultLimit()).willReturn(resultLimit);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(2, optimisedOpChain.getOperations().size());
    assertSame(getOperation, optimisedOpChain.getOperations().get(0));
    assertTrue(optimisedOpChain.getOperations().get(1) instanceof Limit);
    assertEquals(resultLimit, (int) ((Limit) optimisedOpChain.getOperations().get(1)).getResultLimit());
}
Also used : GetIterableOperation(uk.gov.gchq.gaffer.operation.GetIterableOperation) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.Test)

Aggregations

OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)65 Test (org.junit.Test)52 User (uk.gov.gchq.gaffer.user.User)38 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 Store (uk.gov.gchq.gaffer.store.Store)13 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)12 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)11 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)11 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)9 GetAdjacentEntitySeeds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds)8 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 Element (uk.gov.gchq.gaffer.data.element.Element)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)7 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)7 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 InOrder (org.mockito.InOrder)6 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)6 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)6