ReduceRelatedElements

See javadoc - uk.gov.gchq.gaffer.data.element.function.ReduceRelatedElements

Available since Gaffer version 1.19.0

This function takes an Iterable of Elements and combines all related elements using the provided aggregator and related group

Examples

Basic example

In this small example, vertex 1a is related to vertex 1b, and vertex 2a is related to vertex 2b.
As well as this, vertex 1a is connected to vertex 2b with the basicEdge group.
We setup the function to do a few things.
Firstly, we set the visibility property name, then state we want to concatenate the visibility properties.
Next we set the vertex aggregator to the Max Binary Operator. This will be used to compare and reduce vertices with.
Finally, we assert the vertex groups that describe which vertices are related, in this case 'relatesTo'.

In our results we should expect to see that 1b and 2b are source and dest as they were aggregated with the Max operator.
The other properties should be listed in the related properties. As well as this, the visiblities should be concatenated together.

Java
JSON
Full JSON
Python
final List<Element> elements = Arrays.asList(
        new Edge.Builder()
                .source("1a")
                .dest("2b")
                .group("basicEdge")
                .property("visibility", Sets.newHashSet("public"))
                .build(),
        new Edge.Builder()
                .source("1a")
                .dest("1b")
                .group("relatesTo")
                .property("visibility", Sets.newHashSet("public"))
                .build(),
        new Edge.Builder()
                .source("2a")
                .dest("2b")
                .group("relatesTo")
                .property("visibility", Sets.newHashSet("private"))
                .build()
);
final ReduceRelatedElements function = new ReduceRelatedElements();
function.setVisibilityProperty("visibility");
function.setVisibilityAggregator(new CollectionConcat<>());
function.setVertexAggregator(new Max());
function.setRelatedVertexGroups(Collections.singleton("relatesTo"));
{
  "class" : "ReduceRelatedElements",
  "vertexAggregator" : {
    "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Max"
  },
  "visibilityAggregator" : {
    "class" : "CollectionConcat"
  },
  "visibilityProperty" : "visibility",
  "relatedVertexGroups" : [ "relatesTo" ]
}
{
  "class" : "uk.gov.gchq.gaffer.data.element.function.ReduceRelatedElements",
  "vertexAggregator" : {
    "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Max"
  },
  "visibilityAggregator" : {
    "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.CollectionConcat"
  },
  "visibilityProperty" : "visibility",
  "relatedVertexGroups" : [ "relatesTo" ]
}
g.ReduceRelatedElements( 
  visibility_aggregator=g.CollectionConcat(), 
  vertex_aggregator=g.Max(), 
  related_vertex_groups=[ 
    "relatesTo" 
  ], 
  visibility_property="visibility" 
)

Input type:

java.lang.Iterable

Example inputs:

Input TypeInputResult TypeResult
java.util.Arrays$ArrayList[Edge[source=1a,destination=2b,directed=false,group=basicEdge,properties=Properties[visibility=<java.util.HashSet>[public]]], Edge[source=1a,destination=1b,directed=false,group=relatesTo,properties=Properties[visibility=<java.util.HashSet>[public]]], Edge[source=2a,destination=2b,directed=false,group=relatesTo,properties=Properties[visibility=<java.util.HashSet>[private]]]]uk.gov.gchq.koryphe.util.IterableUtil$ChainedIterable[Edge[source=1b,destination=2b,directed=false,group=basicEdge,properties=Properties[visibility=<java.util.HashSet>[public, private],sourceRelatedVertices=<java.util.HashSet>[1a],destinationRelatedVertices=<java.util.HashSet>[2a]]]]
nullnull

Complex example

Java
JSON
Full JSON
Python
final List<Element> elements = Arrays.asList(
        new Edge.Builder()
                .source("1b")
                .dest("2a")
                .group("basicEdge")
                .property("visibility", Sets.newHashSet("public"))
                .build(),
        new Edge.Builder()
                .source("1a")
                .dest("3a")
                .group("basicEdge")
                .property("visibility", Sets.newHashSet("public"))
                .build(),
        new Entity.Builder()
                .vertex("2a")
                .group("basicEntity")
                .property("visibility", Sets.newHashSet("public"))
                .build(),
        new Edge.Builder()
                .source("1b")
                .dest("1a")
                .group("relatesTo")
                .property("visibility", Sets.newHashSet("public"))
                .build(),
        new Edge.Builder()
                .source("2a")
                .dest("2b")
                .group("relatesTo")
                .property("visibility", Sets.newHashSet("public"))
                .build(),
        new Edge.Builder()
                .source("3a")
                .dest("3b")
                .group("relatesTo")
                .property("visibility", Sets.newHashSet("private"))
                .build(),
        new Edge.Builder()
                .source("2a")
                .dest("3b")
                .group("relatesTo")
                .property("visibility", Sets.newHashSet("private"))
                .build(),
        new Edge.Builder()
                .source("2b")
                .dest("3a")
                .group("relatesTo")
                .property("visibility", Sets.newHashSet("public"))
                .build(),
        new Edge.Builder()
                .source("3a")
                .dest("4b")
                .group("relatesTo")
                .property("visibility", Sets.newHashSet("private"))
                .build(),
        new Edge.Builder()
                .source("5b")
                .dest("4a")
                .group("relatesTo")
                .property("visibility", Sets.newHashSet("public"))
                .build()
);
final ReduceRelatedElements function = new ReduceRelatedElements();
function.setVisibilityProperty("visibility");
function.setVisibilityAggregator(new CollectionConcat<>());
function.setVertexAggregator(new Max());
function.setRelatedVertexGroups(Collections.singleton("relatesTo"));
{
  "class" : "ReduceRelatedElements",
  "vertexAggregator" : {
    "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Max"
  },
  "visibilityAggregator" : {
    "class" : "CollectionConcat"
  },
  "visibilityProperty" : "visibility",
  "relatedVertexGroups" : [ "relatesTo" ]
}
{
  "class" : "uk.gov.gchq.gaffer.data.element.function.ReduceRelatedElements",
  "vertexAggregator" : {
    "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Max"
  },
  "visibilityAggregator" : {
    "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.CollectionConcat"
  },
  "visibilityProperty" : "visibility",
  "relatedVertexGroups" : [ "relatesTo" ]
}
g.ReduceRelatedElements( 
  visibility_aggregator=g.CollectionConcat(), 
  vertex_aggregator=g.Max(), 
  related_vertex_groups=[ 
    "relatesTo" 
  ], 
  visibility_property="visibility" 
)

Input type:

java.lang.Iterable

Example inputs:

Input TypeInputResult TypeResult
java.util.Arrays$ArrayList[Edge[source=1b,destination=2a,directed=false,group=basicEdge,properties=Properties[visibility=<java.util.HashSet>[public]]], Edge[source=1a,destination=3a,directed=false,group=basicEdge,properties=Properties[visibility=<java.util.HashSet>[public]]], Entity[vertex=2a,group=basicEntity,properties=Properties[visibility=<java.util.HashSet>[public]]], Edge[source=1a,destination=1b,directed=false,group=relatesTo,properties=Properties[visibility=<java.util.HashSet>[public]]], Edge[source=2a,destination=2b,directed=false,group=relatesTo,properties=Properties[visibility=<java.util.HashSet>[public]]], Edge[source=3a,destination=3b,directed=false,group=relatesTo,properties=Properties[visibility=<java.util.HashSet>[private]]], Edge[source=2a,destination=3b,directed=false,group=relatesTo,properties=Properties[visibility=<java.util.HashSet>[private]]], Edge[source=2b,destination=3a,directed=false,group=relatesTo,properties=Properties[visibility=<java.util.HashSet>[public]]], Edge[source=3a,destination=4b,directed=false,group=relatesTo,properties=Properties[visibility=<java.util.HashSet>[private]]], Edge[source=4a,destination=5b,directed=false,group=relatesTo,properties=Properties[visibility=<java.util.HashSet>[public]]]]uk.gov.gchq.koryphe.util.IterableUtil$ChainedIterable[Edge[source=1b,destination=4b,directed=false,group=basicEdge,properties=Properties[visibility=<java.util.HashSet>[public, private],sourceRelatedVertices=<java.util.HashSet>[1a],destinationRelatedVertices=<java.util.HashSet>[2b, 3a, 2a, 3b]]], Edge[source=1b,destination=4b,directed=false,group=basicEdge,properties=Properties[visibility=<java.util.HashSet>[public, private],sourceRelatedVertices=<java.util.HashSet>[1a],destinationRelatedVertices=<java.util.HashSet>[2b, 3a, 2a, 3b]]], Entity[vertex=4b,group=basicEntity,properties=Properties[visibility=<java.util.HashSet>[public, private],relatedVertices=<java.util.HashSet>[2b, 3a, 2a, 3b]]]]

results matching ""

    No results matching ""