Search in sources :

Example 6 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AddElementsFromHdfsIT method createGraph.

private Graph createGraph(final Class<? extends AccumuloKeyPackage> keyPackageClass) throws StoreException {
    final Schema schema = Schema.fromJson(StreamUtil.schemas(getClass()));
    final AccumuloProperties properties = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    properties.setKeyPackageClass(keyPackageClass.getName());
    properties.setInstance("instance_" + keyPackageClass.getName());
    final AccumuloStore store = new MockAccumuloStore();
    store.initialise(schema, properties);
    store.updateConfiguration(createLocalConf(), new View(), new User());
    return new Graph.Builder().store(store).build();
}
Also used : User(uk.gov.gchq.gaffer.user.User) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 7 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class GetElementsBetweenSetsHandlerTest method shouldReturnSummarisedElements.

private void shouldReturnSummarisedElements(final AccumuloStore store) throws OperationException {
    final View opView = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
    final GetElementsBetweenSets<Element> op = new GetElementsBetweenSets<>(seedsA, seedsB, opView);
    final GetElementsBetweenSetsHandler handler = new GetElementsBetweenSetsHandler();
    final CloseableIterable<Element> elements = handler.doOperation(op, user, store);
    //With query compaction the result size should be 2
    assertEquals(2, Iterables.size(elements));
    assertThat(elements, IsCollectionContaining.hasItems(expectedSummarisedEdge, expectedEntity1));
    elements.close();
}
Also used : GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) 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)

Example 8 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class ViewIT method shouldDeserialiseJsonView.

@Test
public void shouldDeserialiseJsonView() throws IOException {
    // Given
    // When
    View view = loadView();
    // Then
    final ViewElementDefinition edge = view.getEdge(TestGroups.EDGE);
    final ElementTransformer transformer = edge.getTransformer();
    assertNotNull(transformer);
    final List<ConsumerProducerFunctionContext<String, TransformFunction>> contexts = transformer.getFunctions();
    assertEquals(1, contexts.size());
    final List<String> selection = contexts.get(0).getSelection();
    assertEquals(2, selection.size());
    assertEquals(TestPropertyNames.PROP_1, selection.get(0));
    assertEquals(IdentifierType.SOURCE.name(), selection.get(1));
    final List<String> projection = contexts.get(0).getProjection();
    assertEquals(1, projection.size());
    assertEquals(TestPropertyNames.TRANSIENT_1, projection.get(0));
    assertTrue(contexts.get(0).getFunction() instanceof ExampleTransformFunction);
    final ElementFilter postFilter = edge.getPostTransformFilter();
    assertNotNull(postFilter);
    final List<ConsumerFunctionContext<String, FilterFunction>> filterContexts = postFilter.getFunctions();
    assertEquals(1, contexts.size());
    final List<String> postFilterSelection = filterContexts.get(0).getSelection();
    assertEquals(1, postFilterSelection.size());
    assertEquals(TestPropertyNames.TRANSIENT_1, postFilterSelection.get(0));
    assertTrue(filterContexts.get(0).getFunction() instanceof ExampleFilterFunction);
}
Also used : ConsumerProducerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext) ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.Test)

Example 9 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class GraphTest method shouldSetGraphViewOnOperationAndDelegateDoOperationToStore.

@Test
public void shouldSetGraphViewOnOperationAndDelegateDoOperationToStore() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    final View view = mock(View.class);
    final Graph graph = new Graph.Builder().store(store).view(view).build();
    final User user = new User();
    final int expectedResult = 5;
    final Operation<?, Integer> operation = mock(Operation.class);
    given(operation.getView()).willReturn(null);
    final OperationChain<Integer> opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(Collections.<Operation>singletonList(operation));
    given(store.execute(opChain, user)).willReturn(expectedResult);
    // When
    int result = graph.execute(opChain, user);
    // Then
    assertEquals(expectedResult, result);
    verify(store).execute(opChain, user);
    verify(operation).setView(view);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 10 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class GraphTest method shouldConstructGraphAndCreateViewWithGroups.

@Test
public void shouldConstructGraphAndCreateViewWithGroups() {
    // Given
    final Store store = mock(Store.class);
    final Schema schema = mock(Schema.class);
    given(store.getSchema()).willReturn(schema);
    final Set<String> edgeGroups = new HashSet<>();
    edgeGroups.add("edge1");
    edgeGroups.add("edge2");
    edgeGroups.add("edge3");
    edgeGroups.add("edge4");
    given(schema.getEdgeGroups()).willReturn(edgeGroups);
    final Set<String> entityGroups = new HashSet<>();
    entityGroups.add("entity1");
    entityGroups.add("entity2");
    entityGroups.add("entity3");
    entityGroups.add("entity4");
    given(schema.getEntityGroups()).willReturn(entityGroups);
    // When
    final View resultView = new Graph.Builder().store(store).build().getView();
    // Then
    assertNotSame(schema, resultView);
    assertArrayEquals(entityGroups.toArray(), resultView.getEntityGroups().toArray());
    assertArrayEquals(edgeGroups.toArray(), resultView.getEdgeGroups().toArray());
    for (final ViewElementDefinition resultElementDef : resultView.getEntities().values()) {
        assertNotNull(resultElementDef);
        assertEquals(0, resultElementDef.getTransientProperties().size());
        assertNull(resultElementDef.getTransformer());
    }
    for (final ViewElementDefinition resultElementDef : resultView.getEdges().values()) {
        assertNotNull(resultElementDef);
        assertEquals(0, resultElementDef.getTransientProperties().size());
        assertNull(resultElementDef.getTransformer());
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)107 Test (org.junit.Test)70 Element (uk.gov.gchq.gaffer.data.element.Element)42 User (uk.gov.gchq.gaffer.user.User)38 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)32 HashSet (java.util.HashSet)29 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)28 Graph (uk.gov.gchq.gaffer.graph.Graph)20 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)19 ArrayList (java.util.ArrayList)16 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)14 Edge (uk.gov.gchq.gaffer.data.element.Edge)13 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)13 Schema (uk.gov.gchq.gaffer.store.schema.Schema)13 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)12 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)11 SQLContext (org.apache.spark.sql.SQLContext)10 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)9 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)9 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)8