Search in sources :

Example 1 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class AccumuloAggregationIT method shouldHandleAggregatationWhenAllColumnQualifierPropertiesAreGroupByProperties.

@Test
public void shouldHandleAggregatationWhenAllColumnQualifierPropertiesAreGroupByProperties() throws OperationException, UnsupportedEncodingException {
    final Graph graph = createGraphNoVisibility();
    final Entity entity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "test 4").build();
    final Entity entity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "test 4").build();
    graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2)), USER);
    // Given
    final GetEntities<EntitySeed> getElements = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed(VERTEX)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy(AccumuloPropertyNames.COLUMN_QUALIFIER, AccumuloPropertyNames.COLUMN_QUALIFIER_2).build()).build()).build();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getElements, USER));
    // Then
    assertNotNull(results);
    assertEquals(1, results.size());
    final Entity expectedEntity = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "test 4").build();
    assertEquals(expectedEntity, results.get(0));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Graph(uk.gov.gchq.gaffer.graph.Graph) Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test)

Example 2 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class AccumuloAggregationIT method shouldHandleAggregatationWhenGroupByPropertiesAreNotSet.

@Test
public void shouldHandleAggregatationWhenGroupByPropertiesAreNotSet() throws OperationException, UnsupportedEncodingException {
    final Graph graph = createGraphNoVisibility();
    final Entity entity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity entity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2)), USER);
    // Given
    final GetEntities<EntitySeed> getElements = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed(VERTEX)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy(AccumuloPropertyNames.COLUMN_QUALIFIER, AccumuloPropertyNames.COLUMN_QUALIFIER_2).build()).build()).build();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getElements, USER));
    // Then
    assertNotNull(results);
    assertEquals(1, results.size());
    final Entity expectedEntity = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    assertEquals(expectedEntity, results.get(0));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Graph(uk.gov.gchq.gaffer.graph.Graph) Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test)

Example 3 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class AccumuloAggregationIT method shouldHandleAggregatationWhenGroupByPropertiesAreNull.

@Test
public void shouldHandleAggregatationWhenGroupByPropertiesAreNull() throws OperationException, UnsupportedEncodingException {
    final Graph graph = createGraphNoVisibility();
    final Entity entity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, null).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, null).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, null).property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, null).build();
    final Entity entity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2)), USER);
    // Given
    final GetEntities<EntitySeed> getElements = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed(VERTEX)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).build()).build();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getElements, USER));
    // Then
    assertNotNull(results);
    assertEquals(1, results.size());
    final Entity expectedEntity = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    assertEquals(expectedEntity, results.get(0));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Graph(uk.gov.gchq.gaffer.graph.Graph) Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test)

Example 4 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class AccumuloAggregationIT method shouldHandleAggregatationWhenNoAggregatorsAreProvided.

@Test
public void shouldHandleAggregatationWhenNoAggregatorsAreProvided() throws OperationException, UnsupportedEncodingException {
    final Graph graph = createGraphNoAggregators();
    final Entity entity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity entity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, null).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity entity3 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity entity4 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity entity5 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1a").build();
    final Entity entity6 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1b").build();
    final Entity entity7 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "test2a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").build();
    graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2, entity3, entity4, entity5, entity6, entity7)), USER);
    // Duplicate the entities to check they are not aggregated
    graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2, entity3, entity4, entity5, entity6, entity7)), USER);
    // Given
    final GetAllEntities getAllEntities = new GetAllEntities();
    // When
    final List<Entity> results = Lists.newArrayList(graph.execute(getAllEntities, USER));
    // Then
    assertNotNull(results);
    assertEquals(14, results.size());
    final Entity expectedEntity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity expectedEntity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity expectedEntity3 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "test1b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "test 4").build();
    final Entity expectedEntity4 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "test2a").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "test 3").build();
    assertThat(results, IsCollectionContaining.hasItems(expectedEntity1, expectedEntity2, expectedEntity3, expectedEntity4));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) GetAllEntities(uk.gov.gchq.gaffer.operation.impl.get.GetAllEntities) Graph(uk.gov.gchq.gaffer.graph.Graph) Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) Test(org.junit.Test)

Example 5 with Graph

use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.

the class GetJavaRDDOfElementsExample method runExamples.

@Override
public void runExamples() {
    // Need to actively turn logging on and off as needed as Spark produces some logs
    // even when the log level is set to off.
    ROOT_LOGGER.setLevel(Level.OFF);
    final SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("GetJavaRDDOfElementsExample").set("spark.serializer", "org.apache.spark.serializer.KryoSerializer").set("spark.kryo.registrator", "uk.gov.gchq.gaffer.spark.serialisation.kryo.Registrator").set("spark.driver.allowMultipleContexts", "true");
    final JavaSparkContext sc = new JavaSparkContext(sparkConf);
    sc.setLogLevel("OFF");
    final Graph graph = getGraph();
    try {
        getJavaRddOfElements(sc, graph);
        getJavaRddOfElementsReturningEdgesOnly(sc, graph);
    } catch (final OperationException e) {
        throw new RuntimeException(e);
    }
    sc.stop();
    ROOT_LOGGER.setLevel(Level.INFO);
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) SparkConf(org.apache.spark.SparkConf) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

Graph (uk.gov.gchq.gaffer.graph.Graph)311 Test (org.junit.jupiter.api.Test)172 User (uk.gov.gchq.gaffer.user.User)155 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)146 Element (uk.gov.gchq.gaffer.data.element.Element)116 Schema (uk.gov.gchq.gaffer.store.schema.Schema)84 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)83 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)76 Edge (uk.gov.gchq.gaffer.data.element.Edge)75 HashSet (java.util.HashSet)71 Entity (uk.gov.gchq.gaffer.data.element.Entity)68 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)60 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)58 ArrayList (java.util.ArrayList)56 OperationException (uk.gov.gchq.gaffer.operation.OperationException)55 Test (org.junit.Test)49 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)49 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)44 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)44 Set (java.util.Set)38