Skip to content

Core Operations

These Operations form the core of Gaffer. They are always available.

Unless otherwise specified, this directed graph is used in the examples on this page:

graph TD
  1(1, count=3) -- count=3 --> 2
  1 -- count=1 --> 4
  2(2, count=1) -- count=2 --> 3
  2 -- count=1 --> 4(4, count=1)
  2 -- count=1 --> 5(5, count=3)
  3(3, count=2) -- count=4 --> 4

AddElements

Adds elements to a graph. Javadoc

Example adding a new entity and edge

Adding an additonal entity '6' and edge connecting it to '5'

new AddElements.Builder()
            .input(new Entity.Builder()
                            .group("entity")
                            .vertex(6)
                            .property("count", 1)
                            .build(),
                    new Edge.Builder()
                            .group("edge")
                            .source(5).dest(6).directed(true)
                            .property("count", 1)
                            .build())
            .build();
{
  "class" : "AddElements",
  "input" : [ {
    "class" : "Entity",
    "group" : "entity",
    "vertex" : 6,
    "properties" : {
      "count" : 1
    }
  }, {
    "class" : "Edge",
    "group" : "edge",
    "source" : 5,
    "destination" : 6,
    "directed" : true,
    "properties" : {
      "count" : 1
    }
  } ],
  "skipInvalidElements" : false,
  "validate" : true
}
g.AddElements(
  input=[
    g.Entity(
      group="entity",
      properties={'count': 1},
      vertex=6
    ),
    g.Edge(
      group="edge",
      properties={'count': 1},
      source=5,
      destination=6,
      directed=True
    )
  ],
  skip_invalid_elements=False,
  validate=True
)

Results:

graph TD
  1 --> 2
  1 --> 4
  2 --> 3
  2 --> 4
  2 --> 5
  3 --> 4
  5 --> 6

DeleteElements

Deletes Elements from a graph. Javadoc

Note that this operation does not return any response.

Example deleting an entity and edge

Deleting entity '6' and its edge to 5.

final OperationChain<Void> deleteElementsChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
            .input(new EntitySeed(6))
            .build())
        .then(new DeleteElements())
        .build();

graph.execute(deleteElementsChain, new User());
{
    "class" : "OperationChain",
    "operations" : [{
        "class": "GetElements",
        "input": [{
            "class": "EntitySeed",
            "vertex": 6,
        }]
    },
    {
        "class" : "DeleteElements"
    }]
}
g.OperationChain(
    operations=[
        g.GetElements(input=[g.EntitySeed(vertex=6)]),
        g.DeleteElements()
    ]
)

Results:

graph TD
  1 --> 2
  1 --> 4
  2 --> 3
  2 --> 4
  2 --> 5
  3 --> 4

Aggregate

The Aggregate operation would normally be used in an Operation Chain to aggregate the results of a previous operation. Javadoc

Example simple aggregate elements
final Aggregate aggregate = new Aggregate();
{
  "class" : "Aggregate"
}
g.Aggregate()
Example aggregate only edges of type edge with a transient property and provided aggregator

The groupBy has been set to an empty array. This will override the groupBy value in the schema.

final String[] groupBy = {};
final Aggregate aggregate = new Aggregate.Builder()
        .edge("edge", new AggregatePair(
                groupBy,
                new ElementAggregator.Builder()
                        .select("transientProperty1")
                        .execute(new StringConcat())
                        .build()))
        .build();
{
  "class" : "Aggregate",
  "edges" : {
    "edge" : {
      "elementAggregator" : {
        "operators" : [ {
          "selection" : [ "transientProperty1" ],
          "binaryOperator" : {
            "class" : "StringConcat",
            "separator" : ","
          }
        } ]
      },
      "groupBy" : [ ]
    }
  }
}
g.Aggregate(
  edges=[
    g.AggregatePair(
      group="edge",
      group_by=[
      ],
      element_aggregator=g.ElementAggregateDefinition(
        operators=[
          g.BinaryOperatorContext(
            selection=[
              "transientProperty1"
            ],
            binary_operator=g.BinaryOperator(
              class_name="uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat",
              fields={'separator': ','}
            )
          )
        ]
      )
    )
  ]
)

Count

Counts the number of items in an iterable. Javadoc

Example counting all elements
OperationChain<Long> countAllElements = new OperationChain.Builder()
        .first(new GetAllElements())
        .then(new Count<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetAllElements"
  }, {
    "class" : "Count"
  } ]
}
g.OperationChain(
  operations=[
    g.GetAllElements(),
    g.Count()
  ]
)

Results:

11
11

CountGroups

Counts the different element groups. Javadoc

Example counting all element groups
final OperationChain<GroupCounts> opChain = new OperationChain.Builder()
        .first(new GetAllElements())
        .then(new CountGroups())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetAllElements"
  }, {
    "class" : "CountGroups"
  } ]
}
g.OperationChain(
  operations=[
    g.GetAllElements(),
    g.CountGroups()
  ]
)

Results:

GroupCounts[entityGroups={entity=5},edgeGroups={edge=6},limitHit=false]
{
  "entityGroups" : {
    "entity" : 5
  },
  "edgeGroups" : {
    "edge" : 6
  },
  "limitHit" : false
}
Example counting all element groups with limit
final OperationChain<GroupCounts> opChain = new OperationChain.Builder()
        .first(new GetAllElements())
        .then(new CountGroups(5))
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetAllElements"
  }, {
    "class" : "CountGroups",
    "limit" : 5
  } ]
}
g.OperationChain(
  operations=[
    g.GetAllElements(),
    g.CountGroups(
      limit=5
    )
  ]
)

Results:

GroupCounts[entityGroups={entity=3},edgeGroups={edge=2},limitHit=true]
{
  "entityGroups" : {
    "entity" : 3
  },
  "edgeGroups" : {
    "edge" : 2
  },
  "limitHit" : true
}

Filter

Filters elements. Javadoc

Example filtering for elements with a count more than 2

The filter will only return elements (Entities and Edges) with a count more than 2. The results show the Edge between 1 & 4 that has a count of 1 has been removed.

final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder()
        .first(new NamedOperation.Builder<EntitySeed, Iterable<? extends Element>>()
                .name("1-hop")
                .input(new EntitySeed(1))
                .build())
        .then(new Filter.Builder()
                .globalElements(new ElementFilter.Builder()
                        .select("count")
                        .execute(new IsMoreThan(2))
                        .build())
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "NamedOperation",
    "input" : [ {
      "class" : "EntitySeed",
      "class" : "EntitySeed",
      "vertex" : 1
    } ],
    "operationName" : "1-hop"
  }, {
    "class" : "Filter",
    "globalElements" : {
      "predicates" : [ {
        "selection" : [ "count" ],
        "predicate" : {
          "class" : "IsMoreThan",
          "orEqualTo" : false,
          "value" : 2
        }
      } ]
    }
  } ]
}
g.OperationChain(
  operations=[
    g.NamedOperation(
      input=[
        g.EntitySeed(
          vertex=1
        )
      ],
      operation_name="1-hop"
    ),
    g.Filter(
      global_elements=g.GlobalElementFilterDefinition(
        predicates=[
          g.PredicateContext(
            selection=[
              "count"
            ],
            predicate=g.IsMoreThan(
              value=2,
              or_equal_to=False
            )
          )
        ]
      )
    )
  ]
)

Results:

Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 1,
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 3
  }
} ]
Example filtering for edges of type edge with count more than 2

Similar to the previous example but this will only return Edges with group 'edge' that have a count more than 2.

final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder()
        .first(new NamedOperation.Builder<EntitySeed, Iterable<? extends Element>>()
                .name("1-hop")
                .input(new EntitySeed(1))
                .build())
        .then(new Filter.Builder()
                .edge("edge", new ElementFilter.Builder()
                        .select("count")
                        .execute(new IsMoreThan(2))
                        .build())
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "NamedOperation",
    "input" : [ {
      "class" : "EntitySeed",
      "class" : "EntitySeed",
      "vertex" : 1
    } ],
    "operationName" : "1-hop"
  }, {
    "class" : "Filter",
    "edges" : {
      "edge" : {
        "predicates" : [ {
          "selection" : [ "count" ],
          "predicate" : {
            "class" : "IsMoreThan",
            "orEqualTo" : false,
            "value" : 2
          }
        } ]
      }
    }
  } ]
}
g.OperationChain(
  operations=[
    g.NamedOperation(
      input=[
        g.EntitySeed(
          vertex=1
        )
      ],
      operation_name="1-hop"
    ),
    g.Filter(
      edges=[
        g.ElementFilterDefinition(
          group="edge",
          predicates=[
            g.PredicateContext(
              selection=[
                "count"
              ],
              predicate=g.IsMoreThan(
                value=2,
                or_equal_to=False
              )
            )
          ]
        )
      ]
    )
  ]
)

Results:

Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 3
  }
} ]

Limit

Limits the number of elements returned. This truncates output by default, but optionally an exception can be thrown instead of truncating. Javadoc

Example limiting elements to 3
final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder()
        .first(new GetAllElements())
        .then(new Limit<>(3))
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetAllElements"
  }, {
    "class" : "Limit",
    "resultLimit" : 3,
    "truncate" : true
  } ]
}
g.OperationChain(
  operations=[
    g.GetAllElements(),
    g.Limit(
      result_limit=3,
      truncate=True
    )
  ]
)

Results:

Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=5,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=3,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>4]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 5,
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 3,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 4
  }
} ]
Example limiting elements to 3 without truncation

Setting this flag to false will throw an error instead of truncating the iterable. In this case there are more than 3 elements, so when executed a LimitExceededException would be thrown.

final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder()
        .first(new GetAllElements())
        .then(new Limit<>(3, false))
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetAllElements"
  }, {
    "class" : "Limit",
    "resultLimit" : 3,
    "truncate" : false
  } ]
}
g.OperationChain(
  operations=[
    g.GetAllElements(),
    g.Limit(
      result_limit=3,
      truncate=False
    )
  ]
)
Example limiting elements to 3 with builder

A builder can also be used to create the limit - note that truncate is set to true by default, so in this case it is redundant, but simply shown for demonstration.

final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder()
        .first(new GetAllElements())
        .then(new Limit.Builder<Element>()
                .resultLimit(3)
                .truncate(true)
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetAllElements"
  }, {
    "class" : "Limit",
    "resultLimit" : 3,
    "truncate" : true
  } ]
}
g.OperationChain(
  operations=[
    g.GetAllElements(),
    g.Limit(
      result_limit=3,
      truncate=True
    )
  ]
)

Results:

Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=5,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=3,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>4]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 5,
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 3,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 4
  }
} ]

Min

Extracts the minimum element based on provided Comparators. Javadoc

Example min count
final OperationChain<Element> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new Min.Builder()
                .comparators(new ElementPropertyComparator.Builder()
                        .groups("entity", "edge")
                        .property("count")
                        .build())
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.compare.Min",
    "comparators" : [ {
      "class" : "ElementPropertyComparator",
      "property" : "count",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    } ]
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.Min(
      comparators=[
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="count",
          reversed=False
        )
      ]
    )
  ]
)

Results:

Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
{
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}
Example min count and transient property
final OperationChain<Element> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .view(new View.Builder()
                        .entity("entity", new ViewElementDefinition.Builder()
                                .transientProperty("score", Integer.class)
                                .transformer(new ElementTransformer.Builder()
                                        .select("VERTEX", "count")
                                        .execute(new ExampleScoreFunction())
                                        .project("score")
                                        .build())
                                .build())
                        .edge("edge", new ViewElementDefinition.Builder()
                                .transientProperty("score", Integer.class)
                                .transformer(new ElementTransformer.Builder()
                                        .select("DESTINATION", "count")
                                        .execute(new ExampleScoreFunction())
                                        .project("score")
                                        .build())
                                .build())
                        .build())
                .build())
        .then(new Min.Builder()
                .comparators(
                        new ElementPropertyComparator.Builder()
                                .groups("entity", "edge")
                                .property("count")
                                .reverse(false)
                                .build(),
                        new ElementPropertyComparator.Builder()
                                .groups("entity", "edge")
                                .property("score")
                                .reverse(false)
                                .build()
                )
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "view" : {
      "edges" : {
        "edge" : {
          "transientProperties" : {
            "score" : "Integer"
          },
          "transformFunctions" : [ {
            "selection" : [ "DESTINATION", "count" ],
            "function" : {
              "class" : "ExampleScoreFunction"
            },
            "projection" : [ "score" ]
          } ]
        }
      },
      "entities" : {
        "entity" : {
          "transientProperties" : {
            "score" : "Integer"
          },
          "transformFunctions" : [ {
            "selection" : [ "VERTEX", "count" ],
            "function" : {
              "class" : "ExampleScoreFunction"
            },
            "projection" : [ "score" ]
          } ]
        }
      }
    }
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.compare.Min",
    "comparators" : [ {
      "class" : "ElementPropertyComparator",
      "property" : "count",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    }, {
      "class" : "ElementPropertyComparator",
      "property" : "score",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    } ]
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      view=g.View(
        entities=[
          g.ElementDefinition(
            group="entity",
            transient_properties={'score': 'java.lang.Integer'},
            transform_functions=[
              g.FunctionContext(
                selection=[
                  "VERTEX",
                  "count"
                ],
                function=g.Function(
                  class_name="uk.gov.gchq.gaffer.doc.operation.function.ExampleScoreFunction",
                  fields={}
                ),
                projection=[
                  "score"
                ]
              )
            ]
          )
        ],
        edges=[
          g.ElementDefinition(
            group="edge",
            transient_properties={'score': 'java.lang.Integer'},
            transform_functions=[
              g.FunctionContext(
                selection=[
                  "DESTINATION",
                  "count"
                ],
                function=g.Function(
                  class_name="uk.gov.gchq.gaffer.doc.operation.function.ExampleScoreFunction",
                  fields={}
                ),
                projection=[
                  "score"
                ]
              )
            ]
          )
        ],
        all_edges=False,
        all_entities=False
      ),
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.Min(
      comparators=[
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="count",
          reversed=False
        ),
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="score",
          reversed=False
        )
      ]
    )
  ]
)

Results:

Entity[vertex=2,group=entity,properties=Properties[score=<java.lang.Integer>2,count=<java.lang.Integer>1]]
{
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 2,
  "properties" : {
    "score" : 2,
    "count" : 1
  }
}

Max

Extracts the maximum element based on provided Comparators. Javadoc

Example max count
final OperationChain<Element> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new Max.Builder()
                .comparators(new ElementPropertyComparator.Builder()
                        .groups("entity", "edge")
                        .property("count")
                        .build())
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.compare.Max",
    "comparators" : [ {
      "class" : "ElementPropertyComparator",
      "property" : "count",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    } ]
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.Max(
      comparators=[
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="count",
          reversed=False
        )
      ]
    )
  ]
)

Results:

Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]
{
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 1,
  "properties" : {
    "count" : 3
  }
}
Example max count and transient property
final OperationChain<Element> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .view(new View.Builder()
                        .entity("entity", new ViewElementDefinition.Builder()
                                .transientProperty("score", Integer.class)
                                .transformer(new ElementTransformer.Builder()
                                        .select("VERTEX", "count")
                                        .execute(new ExampleScoreFunction())
                                        .project("score")
                                        .build())
                                .build())
                        .edge("edge", new ViewElementDefinition.Builder()
                                .transientProperty("score", Integer.class)
                                .transformer(new ElementTransformer.Builder()
                                        .select("DESTINATION", "count")
                                        .execute(new ExampleScoreFunction())
                                        .project("score")
                                        .build())
                                .build())
                        .build())
                .build())
        .then(new Max.Builder()
                .comparators(
                        new ElementPropertyComparator.Builder()
                                .groups("entity", "edge")
                                .property("count")
                                .reverse(false)
                                .build(),
                        new ElementPropertyComparator.Builder()
                                .groups("entity", "edge")
                                .property("score")
                                .reverse(false)
                                .build()
                )
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "view" : {
      "edges" : {
        "edge" : {
          "transientProperties" : {
            "score" : "Integer"
          },
          "transformFunctions" : [ {
            "selection" : [ "DESTINATION", "count" ],
            "function" : {
              "class" : "ExampleScoreFunction"
            },
            "projection" : [ "score" ]
          } ]
        }
      },
      "entities" : {
        "entity" : {
          "transientProperties" : {
            "score" : "Integer"
          },
          "transformFunctions" : [ {
            "selection" : [ "VERTEX", "count" ],
            "function" : {
              "class" : "ExampleScoreFunction"
            },
            "projection" : [ "score" ]
          } ]
        }
      }
    }
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.compare.Max",
    "comparators" : [ {
      "class" : "ElementPropertyComparator",
      "property" : "count",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    }, {
      "class" : "ElementPropertyComparator",
      "property" : "score",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    } ]
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      view=g.View(
        entities=[
          g.ElementDefinition(
            group="entity",
            transient_properties={'score': 'java.lang.Integer'},
            transform_functions=[
              g.FunctionContext(
                selection=[
                  "VERTEX",
                  "count"
                ],
                function=g.Function(
                  class_name="uk.gov.gchq.gaffer.doc.operation.function.ExampleScoreFunction",
                  fields={}
                ),
                projection=[
                  "score"
                ]
              )
            ]
          )
        ],
        edges=[
          g.ElementDefinition(
            group="edge",
            transient_properties={'score': 'java.lang.Integer'},
            transform_functions=[
              g.FunctionContext(
                selection=[
                  "DESTINATION",
                  "count"
                ],
                function=g.Function(
                  class_name="uk.gov.gchq.gaffer.doc.operation.function.ExampleScoreFunction",
                  fields={}
                ),
                projection=[
                  "score"
                ]
              )
            ]
          )
        ],
        all_edges=False,
        all_entities=False
      ),
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.Max(
      comparators=[
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="count",
          reversed=False
        ),
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="score",
          reversed=False
        )
      ]
    )
  ]
)

Results:

Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[score=<java.lang.Integer>6,count=<java.lang.Integer>3]]
{
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "score" : 6,
    "count" : 3
  }
}

Sort

Sorts elements based on provided Comparators and can be used to extract the top 'n' elements. Javadoc

Example sorting on count
final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new Sort.Builder()
                .comparators(new ElementPropertyComparator.Builder()
                        .groups("entity", "edge")
                        .property("count")
                        .reverse(false)
                        .build())
                .resultLimit(10)
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "Sort",
    "comparators" : [ {
      "class" : "ElementPropertyComparator",
      "property" : "count",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    } ],
    "deduplicate" : true,
    "resultLimit" : 10
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.Sort(
      comparators=[
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="count",
          reversed=False
        )
      ],
      result_limit=10,
      deduplicate=True
    )
  ]
)

Results:

Edge[source=2,destination=5,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=2,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=2,group=entity,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=2,destination=3,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>2]]
Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 5,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 2,
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 3,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 2
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 1,
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 3
  }
} ]
Example sorting on count without deduplicating

Deduplication is true by default.

final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new Sort.Builder()
                .comparators(new ElementPropertyComparator.Builder()
                        .groups("entity", "edge")
                        .property("count")
                        .reverse(false)
                        .build())
                .resultLimit(10)
                .deduplicate(false)
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "Sort",
    "comparators" : [ {
      "class" : "ElementPropertyComparator",
      "property" : "count",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    } ],
    "deduplicate" : false,
    "resultLimit" : 10
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.Sort(
      comparators=[
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="count",
          reversed=False
        )
      ],
      result_limit=10,
      deduplicate=False
    )
  ]
)

Results:

Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=2,group=entity,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=2,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=2,destination=5,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=2,destination=3,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>2]]
Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 2,
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 5,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 3,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 2
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 1,
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 3
  }
} ]
Example sorting on count and transient property
final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .view(new View.Builder()
                        .entity("entity", new ViewElementDefinition.Builder()
                                .transientProperty("score", Integer.class)
                                .transformer(new ElementTransformer.Builder()
                                        .select("VERTEX", "count")
                                        .execute(new ExampleScoreFunction())
                                        .project("score")
                                        .build())
                                .build())
                        .edge("edge", new ViewElementDefinition.Builder()
                                .transientProperty("score", Integer.class)
                                .transformer(new ElementTransformer.Builder()
                                        .select("DESTINATION", "count")
                                        .execute(new ExampleScoreFunction())
                                        .project("score")
                                        .build())
                                .build())
                        .build())
                .build())
        .then(new Sort.Builder()
                .comparators(
                        new ElementPropertyComparator.Builder()
                                .groups("entity", "edge")
                                .property("count")
                                .reverse(false)
                                .build(),
                        new ElementPropertyComparator.Builder()
                                .groups("entity", "edge")
                                .property("score")
                                .reverse(false)
                                .build()
                )
                .resultLimit(4)
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "view" : {
      "edges" : {
        "edge" : {
          "transientProperties" : {
            "score" : "Integer"
          },
          "transformFunctions" : [ {
            "selection" : [ "DESTINATION", "count" ],
            "function" : {
              "class" : "ExampleScoreFunction"
            },
            "projection" : [ "score" ]
          } ]
        }
      },
      "entities" : {
        "entity" : {
          "transientProperties" : {
            "score" : "Integer"
          },
          "transformFunctions" : [ {
            "selection" : [ "VERTEX", "count" ],
            "function" : {
              "class" : "ExampleScoreFunction"
            },
            "projection" : [ "score" ]
          } ]
        }
      }
    }
  }, {
    "class" : "Sort",
    "comparators" : [ {
      "class" : "ElementPropertyComparator",
      "property" : "count",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    }, {
      "class" : "ElementPropertyComparator",
      "property" : "score",
      "groups" : [ "entity", "edge" ],
      "reversed" : false
    } ],
    "deduplicate" : true,
    "resultLimit" : 4
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      view=g.View(
        entities=[
          g.ElementDefinition(
            group="entity",
            transient_properties={'score': 'java.lang.Integer'},
            transform_functions=[
              g.FunctionContext(
                selection=[
                  "VERTEX",
                  "count"
                ],
                function=g.Function(
                  class_name="uk.gov.gchq.gaffer.doc.operation.function.ExampleScoreFunction",
                  fields={}
                ),
                projection=[
                  "score"
                ]
              )
            ]
          )
        ],
        edges=[
          g.ElementDefinition(
            group="edge",
            transient_properties={'score': 'java.lang.Integer'},
            transform_functions=[
              g.FunctionContext(
                selection=[
                  "DESTINATION",
                  "count"
                ],
                function=g.Function(
                  class_name="uk.gov.gchq.gaffer.doc.operation.function.ExampleScoreFunction",
                  fields={}
                ),
                projection=[
                  "score"
                ]
              )
            ]
          )
        ],
        all_edges=False,
        all_entities=False
      ),
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.Sort(
      comparators=[
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="count",
          reversed=False
        ),
        g.ElementPropertyComparator(
          groups=[
            "entity",
            "edge"
          ],
          property="score",
          reversed=False
        )
      ],
      result_limit=4,
      deduplicate=True
    )
  ]
)

Results:

Entity[vertex=2,group=entity,properties=Properties[score=<java.lang.Integer>2,count=<java.lang.Integer>1]]
Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[score=<java.lang.Integer>4,count=<java.lang.Integer>1]]
Edge[source=2,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[score=<java.lang.Integer>4,count=<java.lang.Integer>1]]
Edge[source=2,destination=5,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[score=<java.lang.Integer>5,count=<java.lang.Integer>1]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 2,
  "properties" : {
    "score" : 2,
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "score" : 4,
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "score" : 4,
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 5,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "score" : 5,
    "count" : 1
  }
} ]

Reduce

Reduces an input to an output with a single value using provided function. Javadoc

Example of reduce
final OperationChain<Iterable<?>> opChain = new OperationChain.Builder()
        .first(new GetAdjacentIds.Builder()
                .input(new EntitySeed(1))
                .build())
        .then(new ForEach.Builder<>()
                .operation(new OperationChain.Builder()
                        .first(new ToSingletonList<EntitySeed>())
                        .then(new GetAdjacentIds())
                        .then(new ToVertices())
                        .then(new Reduce.Builder<>()
                                .aggregateFunction(new Sum())
                                .build())
                        .build())
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetAdjacentIds",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    } ]
  }, {
    "class" : "ForEach",
    "operation" : {
      "class" : "OperationChain",
      "operations" : [ {
        "class" : "ToSingletonList"
      }, {
        "class" : "GetAdjacentIds"
      }, {
        "class" : "ToVertices"
      }, {
        "class" : "Reduce",
        "aggregateFunction" : {
          "class" : "Sum"
        }
      } ]
    }
  } ]
}
g.OperationChain(
  operations=[
    g.GetAdjacentIds(
      input=[
        g.EntitySeed(
          vertex=1
        )
      ]
    ),
    g.ForEach(
      operation=g.OperationChain(
        operations=[
          g.ToSingletonList(),
          g.GetAdjacentIds(),
          g.ToVertices(),
          g.Reduce(
            aggregate_function=g.Sum()
          )
        ]
      )
    )
  ]
)

Results:

6
13
[ 6, 13 ]

Map

Maps an input to an output using provided functions. Javadoc

Example extracting from get elements

This simple example demonstrates retrieving elements from the "entity" group, from which the first item is extracted.

final OperationChain<?> operationChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .view(new View.Builder()
                        .entity("entity")
                        .build())
                .build())
        .then(new Map.Builder<Iterable<? extends Element>>()
                .first(new FirstItem<>())
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "view" : {
      "entities" : {
        "entity" : { }
      }
    }
  }, {
    "class" : "Map",
    "functions" : [ {
      "class" : "FirstItem"
    } ]
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      view=g.View(
        entities=[
          g.ElementDefinition(
            group="entity"
          )
        ],
        all_edges=False,
        all_entities=False
      ),
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.Map(
      functions=[
        g.FirstItem()
      ]
    )
  ]
)

Results:

Entity[vertex=2,group=entity,properties=Properties[count=<java.lang.Integer>1]]
{
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 2,
  "properties" : {
    "count" : 1
  }
}
Example extracting first items from walks

This example demonstrates the extraction of the input seeds to a GetWalks operation, using the Map operation with ExtractWalkEdgesFromHop, and FirstItem functions.

final OperationChain<Set<?>> opChain = new OperationChain.Builder()
        .first(new GetWalks.Builder()
                .operations(new GetElements.Builder()
                        .view(new View.Builder()
                                .edge("edge")
                                .build())
                        .build())
                .resultsLimit(100)
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new Map.Builder<Iterable<Walk>>()
                .first(new IterableFunction.Builder<Walk>()
                        .first(new ExtractWalkEdgesFromHop(0))
                        .then(new FirstItem<>())
                        .build())
                .build())
        .then(new ToVertices.Builder()
                .edgeVertices(ToVertices.EdgeVertices.SOURCE)
                .build())
        .then(new ToSet<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetWalks",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "operations" : [ {
      "class" : "OperationChain",
      "operations" : [ {
        "class" : "GetElements",
        "view" : {
          "edges" : {
            "edge" : { }
          }
        }
      } ]
    } ],
    "resultsLimit" : 100
  }, {
    "class" : "Map",
    "functions" : [ {
      "class" : "IterableFunction",
      "functions" : [ {
        "class" : "ExtractWalkEdgesFromHop",
        "hop" : 0
      }, {
        "class" : "FirstItem"
      } ]
    } ]
  }, {
    "class" : "ToVertices",
    "edgeVertices" : "SOURCE"
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.output.ToSet"
  } ]
}
g.OperationChain(
  operations=[
    g.GetWalks(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ],
      operations=[
        g.OperationChain(
          operations=[
            g.GetElements(
              view=g.View(
                edges=[
                  g.ElementDefinition(
                    group="edge"
                  )
                ],
                all_edges=False,
                all_entities=False
              )
            )
          ]
        )
      ],
      results_limit=100
    ),
    g.Map(
      functions=[
        g.IterableFunction(
          functions=[
            g.ExtractWalkEdgesFromHop(
              hop=0
            ),
            g.FirstItem()
          ]
        )
      ]
    ),
    g.ToVertices(
      edge_vertices="SOURCE"
    ),
    g.ToSet()
  ]
)

Results:

1
2
[ 1, 2 ]

Transform

The Transform operation would normally be used in an Operation Chain to transform the results of a previous operation. Javadoc

Example transforming count property into count string property only for edges of type edge
final Transform transform = new Transform.Builder()
        .edge("edge", new ElementTransformer.Builder()
                .select("count")
                .execute(new ToString())
                .project("countString")
                .build())
        .build();
{
  "class" : "Transform",
  "edges" : {
    "edge" : {
      "functions" : [ {
        "selection" : [ "count" ],
        "function" : {
          "class" : "ToString"
        },
        "projection" : [ "countString" ]
      } ]
    }
  }
}
g.Transform(
  edges=[
    g.ElementTransformDefinition(
      group="edge",
      functions=[
        g.FunctionContext(
          selection=[
            "count"
          ],
          function=g.ToString(),
          projection=[
            "countString"
          ]
        )
      ]
    )
  ]
)

ToArray

Converts elements to Array. Javadoc

Note

Conversion into an Array is done in memory, so it is not advised for a large number of results.

Example ToArray
final OperationChain<? extends Element[]> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new ToArray<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.output.ToArray"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.ToArray()
  ]
)

Results:

Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=2,group=entity,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=2,destination=3,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>2]]
Edge[source=2,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=2,destination=5,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 2,
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 1,
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 3,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 2
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 5,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
} ]

ToCsv

Converts elements to CSV Strings. Javadoc

Example ToCsv
final OperationChain<Iterable<? extends String>> opChain = new Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new ToCsv.Builder()
                .includeHeader(true)
                .generator(new CsvGenerator.Builder()
                        .group("Edge group")
                        .vertex("vertex")
                        .source("source")
                        .property("count", "total count")
                        .build())
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "ToCsv",
    "elementGenerator" : {
      "class" : "CsvGenerator",
      "fields" : {
        "GROUP" : "Edge group",
        "VERTEX" : "vertex",
        "SOURCE" : "source",
        "count" : "total count"
      },
      "constants" : { },
      "quoted" : false,
      "commaReplacement" : " "
    },
    "includeHeader" : true
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.ToCsv(
      element_generator=g.CsvGenerator(
        fields={'GROUP': 'Edge group', 'VERTEX': 'vertex', 'SOURCE': 'source', 'count': 'total count'},
        constants={},
        quoted=False,
        comma_replacement=" "
      ),
      include_header=True
    )
  ]
)

Results:

Edge group,vertex,source,total count
edge,,1,1
entity,2,,1
entity,1,,3
edge,,2,2
edge,,2,1
edge,,1,3
edge,,2,1
[ "Edge group,vertex,source,total count", "edge,,1,1", "entity,2,,1", "entity,1,,3", "edge,,2,2", "edge,,2,1", "edge,,1,3", "edge,,2,1" ]

ToEntitySeeds

Converts object(s) into EntitySeeds. Javadoc

Example ToEntitySeeds
final OperationChain<Iterable<? extends EntitySeed>> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new ToEntitySeeds())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "ToEntitySeeds"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.ToEntitySeeds()
  ]
)

Results:

EntitySeed[vertex=Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]]
EntitySeed[vertex=Entity[vertex=2,group=entity,properties=Properties[count=<java.lang.Integer>1]]]
EntitySeed[vertex=Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]]
EntitySeed[vertex=Edge[source=2,destination=3,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>2]]]
EntitySeed[vertex=Edge[source=2,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]]
EntitySeed[vertex=Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]]
EntitySeed[vertex=Edge[source=2,destination=5,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]]
[ {
  "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
  "vertex" : {
    "uk.gov.gchq.gaffer.data.element.Edge" : {
      "class" : "uk.gov.gchq.gaffer.data.element.Edge",
      "group" : "edge",
      "source" : 1,
      "destination" : 4,
      "directed" : true,
      "matchedVertex" : "SOURCE",
      "properties" : {
        "count" : 1
      }
    }
  }
}, {
  "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
  "vertex" : {
    "uk.gov.gchq.gaffer.data.element.Entity" : {
      "class" : "uk.gov.gchq.gaffer.data.element.Entity",
      "group" : "entity",
      "vertex" : 2,
      "properties" : {
        "count" : 1
      }
    }
  }
}, {
  "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
  "vertex" : {
    "uk.gov.gchq.gaffer.data.element.Entity" : {
      "class" : "uk.gov.gchq.gaffer.data.element.Entity",
      "group" : "entity",
      "vertex" : 1,
      "properties" : {
        "count" : 3
      }
    }
  }
}, {
  "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
  "vertex" : {
    "uk.gov.gchq.gaffer.data.element.Edge" : {
      "class" : "uk.gov.gchq.gaffer.data.element.Edge",
      "group" : "edge",
      "source" : 2,
      "destination" : 3,
      "directed" : true,
      "matchedVertex" : "SOURCE",
      "properties" : {
        "count" : 2
      }
    }
  }
}, {
  "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
  "vertex" : {
    "uk.gov.gchq.gaffer.data.element.Edge" : {
      "class" : "uk.gov.gchq.gaffer.data.element.Edge",
      "group" : "edge",
      "source" : 2,
      "destination" : 4,
      "directed" : true,
      "matchedVertex" : "SOURCE",
      "properties" : {
        "count" : 1
      }
    }
  }
}, {
  "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
  "vertex" : {
    "uk.gov.gchq.gaffer.data.element.Edge" : {
      "class" : "uk.gov.gchq.gaffer.data.element.Edge",
      "group" : "edge",
      "source" : 1,
      "destination" : 2,
      "directed" : true,
      "matchedVertex" : "SOURCE",
      "properties" : {
        "count" : 3
      }
    }
  }
}, {
  "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
  "vertex" : {
    "uk.gov.gchq.gaffer.data.element.Edge" : {
      "class" : "uk.gov.gchq.gaffer.data.element.Edge",
      "group" : "edge",
      "source" : 2,
      "destination" : 5,
      "directed" : true,
      "matchedVertex" : "SOURCE",
      "properties" : {
        "count" : 1
      }
    }
  }
} ]

ToList

Converts elements to a List. Javadoc

Note

Conversion into a List is done using an in memory ArrayList, so it is not advised for a large number of results.

Example ToList
final OperationChain<List<? extends Element>> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new ToList<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.output.ToList"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.ToList()
  ]
)

Results:

Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=2,group=entity,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=2,destination=3,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>2]]
Edge[source=2,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=2,destination=5,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 2,
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 1,
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 3,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 2
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 5,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
} ]

ToMap

Converts elements to a Map of key-value pairs. Javadoc

Example ToMap
final OperationChain<Iterable<? extends Map<String, Object>>> opChain = new Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new ToMap.Builder()
                .generator(new MapGenerator.Builder()
                        .group("group")
                        .vertex("vertex")
                        .source("source")
                        .property("count", "total count")
                        .build())
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "ToMap",
    "elementGenerator" : {
      "class" : "MapGenerator",
      "fields" : {
        "GROUP" : "group",
        "VERTEX" : "vertex",
        "SOURCE" : "source",
        "count" : "total count"
      },
      "constants" : { }
    }
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.ToMap(
      element_generator=g.MapGenerator(
        fields={'GROUP': 'group', 'VERTEX': 'vertex', 'SOURCE': 'source', 'count': 'total count'},
        constants={}
      )
    )
  ]
)

Results:

{group=edge, source=1, total count=1}
{group=entity, vertex=2, total count=1}
{group=entity, vertex=1, total count=3}
{group=edge, source=2, total count=2}
{group=edge, source=2, total count=1}
{group=edge, source=1, total count=3}
{group=edge, source=2, total count=1}
[ {
  "group" : "edge",
  "source" : 1,
  "total count" : 1
}, {
  "group" : "entity",
  "vertex" : 2,
  "total count" : 1
}, {
  "group" : "entity",
  "vertex" : 1,
  "total count" : 3
}, {
  "group" : "edge",
  "source" : 2,
  "total count" : 2
}, {
  "group" : "edge",
  "source" : 2,
  "total count" : 1
}, {
  "group" : "edge",
  "source" : 1,
  "total count" : 3
}, {
  "group" : "edge",
  "source" : 2,
  "total count" : 1
} ]

ToSet

Converts elements to a Set. Javadoc

Note

Conversion into a Set is done using an in memory LinkedHashSet, so it is not advised for a large number of results.

Example ToSet
final OperationChain<Set<? extends Element>> opChain = new OperationChain.Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new ToSet<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.output.ToSet"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.ToSet()
  ]
)

Results:

Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=2,group=entity,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=2,destination=3,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>2]]
Edge[source=2,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=2,destination=5,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 2,
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 1,
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 3,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 2
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 4,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 2,
  "destination" : 5,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 1
  }
} ]

ToSingletonList

Converts a single input of type T to a List. Javadoc

Example ToSingletonList
final ToSingletonList<Integer> opChain = new ToSingletonList.Builder<Integer>()
        .input(4)
        .build();
{
  "class" : "ToSingletonList",
  "input" : 4
}
g.ToSingletonList(
  input=4
)

Results:

4
[ 4 ]
Example of ToSingletonList in an Operation Chain
final OperationChain<Iterable<?>> opChain = new OperationChain.Builder()
        .first(new GetAdjacentIds.Builder()
                .input(new EntitySeed(1))
                .build())
        .then(new ForEach.Builder<>()
                .operation(new OperationChain.Builder()
                        .first(new ToSingletonList<EntitySeed>())
                        .then(new GetAdjacentIds())
                        .then(new ToVertices())
                        .build())
                .build())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetAdjacentIds",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    } ]
  }, {
    "class" : "ForEach",
    "operation" : {
      "class" : "OperationChain",
      "operations" : [ {
        "class" : "ToSingletonList"
      }, {
        "class" : "GetAdjacentIds"
      }, {
        "class" : "ToVertices"
      } ]
    }
  } ]
}
g.OperationChain(
  operations=[
    g.GetAdjacentIds(
      input=[
        g.EntitySeed(
          vertex=1
        )
      ]
    ),
    g.ForEach(
      operation=g.OperationChain(
        operations=[
          g.ToSingletonList(),
          g.GetAdjacentIds(),
          g.ToVertices()
        ]
      )
    )
  ]
)

Results:

[ 2 --> 3 --> 1 ]
[ 3 --> 4 --> 5 --> 1 ]
[ [ 2, 3, 1 ], [ 3, 4, 5, 1 ] ]

ToStream

Converts elements to a Stream. Javadoc

Note

Conversion into a Stream is done in memory, so it is not advised for a large number of results.

Example ToStream
final OperationChain<Stream<? extends Element>> opChain = new Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .build())
        .then(new ToStream<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ]
  }, {
    "class" : "ToStream"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.ToStream()
  ]
)

Results:

Edge[source=1,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=2,group=entity,properties=Properties[count=<java.lang.Integer>1]]
Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=2,destination=3,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>2]]
Edge[source=2,destination=4,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=2,destination=5,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>1]]
{
  "parallel" : false
}

ToVertices

Converts ElementIds into vertices. Javadoc

The examples use a ToSet operation after the ToVertices operation to deduplicate the results.

Example extracting entity vertices
final OperationChain<Set<?>> opChain = new Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .view(new View.Builder()
                        .entity("entity")
                        .build())
                .build())
        .then(new ToVertices.Builder()
                .edgeVertices(ToVertices.EdgeVertices.NONE)
                .build())
        .then(new ToSet<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "view" : {
      "entities" : {
        "entity" : { }
      }
    }
  }, {
    "class" : "ToVertices",
    "edgeVertices" : "NONE"
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.output.ToSet"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      view=g.View(
        entities=[
          g.ElementDefinition(
            group="entity"
          )
        ],
        all_edges=False,
        all_entities=False
      ),
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ]
    ),
    g.ToVertices(
      edge_vertices="NONE"
    ),
    g.ToSet()
  ]
)

Results:

2
1
[ 2, 1 ]
Example extracting destination vertex
final OperationChain<Set<?>> opChain = new Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING)
                .view(new View.Builder()
                        .edge("edge")
                        .build())
                .build())
        .then(new ToVertices.Builder()
                .edgeVertices(ToVertices.EdgeVertices.DESTINATION)
                .build())
        .then(new ToSet<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "view" : {
      "edges" : {
        "edge" : { }
      }
    },
    "includeIncomingOutGoing" : "OUTGOING"
  }, {
    "class" : "ToVertices",
    "edgeVertices" : "DESTINATION"
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.output.ToSet"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      view=g.View(
        edges=[
          g.ElementDefinition(
            group="edge"
          )
        ],
        all_edges=False,
        all_entities=False
      ),
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ],
      include_incoming_out_going="OUTGOING"
    ),
    g.ToVertices(
      edge_vertices="DESTINATION"
    ),
    g.ToSet()
  ]
)

Results:

4
3
2
5
[ 4, 3, 2, 5 ]
Example extracting both source and destination vertices
final OperationChain<Set<?>> opChain = new Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING)
                .view(new View.Builder()
                        .edge("edge")
                        .build())
                .build())
        .then(new ToVertices.Builder()
                .edgeVertices(ToVertices.EdgeVertices.BOTH)
                .build())
        .then(new ToSet<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "view" : {
      "edges" : {
        "edge" : { }
      }
    },
    "includeIncomingOutGoing" : "OUTGOING"
  }, {
    "class" : "ToVertices",
    "edgeVertices" : "BOTH"
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.output.ToSet"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      view=g.View(
        edges=[
          g.ElementDefinition(
            group="edge"
          )
        ],
        all_edges=False,
        all_entities=False
      ),
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ],
      include_incoming_out_going="OUTGOING"
    ),
    g.ToVertices(
      edge_vertices="BOTH"
    ),
    g.ToSet()
  ]
)

Results:

1
4
2
3
5
[ 1, 4, 2, 3, 5 ]
Example extracting matched vertices
final OperationChain<Set<?>> opChain = new Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING)
                .view(new View.Builder()
                        .edge("edge")
                        .build())
                .build())
        .then(new ToVertices.Builder()
                .useMatchedVertex(ToVertices.UseMatchedVertex.EQUAL)
                .build())
        .then(new ToSet<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "view" : {
      "edges" : {
        "edge" : { }
      }
    },
    "includeIncomingOutGoing" : "OUTGOING"
  }, {
    "class" : "ToVertices",
    "useMatchedVertex" : "EQUAL"
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.output.ToSet"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      view=g.View(
        edges=[
          g.ElementDefinition(
            group="edge"
          )
        ],
        all_edges=False,
        all_entities=False
      ),
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ],
      include_incoming_out_going="OUTGOING"
    ),
    g.ToVertices(
      use_matched_vertex="EQUAL"
    ),
    g.ToSet()
  ]
)

Results:

1
2
[ 1, 2 ]
Example extracting opposite matched vertices
final OperationChain<Set<?>> opChain = new Builder()
        .first(new GetElements.Builder()
                .input(new EntitySeed(1), new EntitySeed(2))
                .inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING)
                .view(new View.Builder()
                        .edge("edge")
                        .build())
                .build())
        .then(new ToVertices.Builder()
                .useMatchedVertex(ToVertices.UseMatchedVertex.OPPOSITE)
                .build())
        .then(new ToSet<>())
        .build();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "GetElements",
    "input" : [ {
      "class" : "EntitySeed",
      "vertex" : 1
    }, {
      "class" : "EntitySeed",
      "vertex" : 2
    } ],
    "view" : {
      "edges" : {
        "edge" : { }
      }
    },
    "includeIncomingOutGoing" : "OUTGOING"
  }, {
    "class" : "ToVertices",
    "useMatchedVertex" : "OPPOSITE"
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.output.ToSet"
  } ]
}
g.OperationChain(
  operations=[
    g.GetElements(
      view=g.View(
        edges=[
          g.ElementDefinition(
            group="edge"
          )
        ],
        all_edges=False,
        all_entities=False
      ),
      input=[
        g.EntitySeed(
          vertex=1
        ),
        g.EntitySeed(
          vertex=2
        )
      ],
      include_incoming_out_going="OUTGOING"
    ),
    g.ToVertices(
      use_matched_vertex="OPPOSITE"
    ),
    g.ToSet()
  ]
)

Results:

4
3
2
5
[ 4, 3, 2, 5 ]

GetGraphCreatedTime

Gets the creation date of the current graph. Javadoc

Example getting the graph created time
final GetGraphCreatedTime operation = new GetGraphCreatedTime();
{
        "class": "uk.gov.gchq.gaffer.operation.impl.get.GetGraphCreatedTime"
}
g.GetGraphCreatedTime()

Results:

{graphId=2024-08-22T12:37:53.498}
{
  "graphId": "2024-08-22T12:37:53.498"
}

GetSchema

Gets the Schema of a Graph. Javadoc

Example getting full schema

This operation defaults the compact field to false, thereby returning the full Schema.

final GetSchema operation = new GetSchema();
{
  "class" : "GetSchema",
  "compact" : false
}
g.GetSchema(
  compact=False
)

Results:

{
  "edges" : {
    "edge" : {
      "description" : "test edge",
      "source" : "int",
      "destination" : "int",
      "directed" : "true",
      "properties" : {
        "count" : "count"
      }
    },
    "edge1" : {
      "source" : "int",
      "destination" : "int",
      "directed" : "true",
      "properties" : {
        "count" : "count"
      }
    }
  },
  "entities" : {
    "entity1" : {
      "vertex" : "int",
      "properties" : {
        "count" : "count"
      }
    },
    "entity" : {
      "description" : "test entity",
      "vertex" : "int",
      "properties" : {
        "count" : "count"
      }
    },
    "cardinality" : {
      "description" : "An entity that is added to every vertex representing the connectivity of the vertex.",
      "vertex" : "int",
      "properties" : {
        "edgeGroup" : "set",
        "hllp" : "hllp",
        "count" : "count"
      },
      "groupBy" : [ "edgeGroup" ]
    }
  },
  "types" : {
    "int" : {
      "class" : "Integer",
      "aggregateFunction" : {
        "class" : "Sum"
      }
    },
    "true" : {
      "class" : "Boolean",
      "validateFunctions" : [ {
        "class" : "IsTrue"
      } ]
    },
    "count" : {
      "class" : "Integer",
      "aggregateFunction" : {
        "class" : "Sum"
      }
    },
    "set" : {
      "class" : "TreeSet",
      "aggregateFunction" : {
        "class" : "CollectionConcat"
      }
    },
    "hllp" : {
      "class" : "com.clearspring.analytics.stream.cardinality.HyperLogLogPlus",
      "aggregateFunction" : {
        "class" : "HyperLogLogPlusAggregator"
      },
      "serialiser" : {
        "class" : "HyperLogLogPlusSerialiser"
      }
    }
  }
}
{
  "edges" : {
    "edge" : {
      "description" : "test edge",
      "source" : "int",
      "destination" : "int",
      "directed" : "true",
      "properties" : {
        "count" : "count"
      }
    },
    "edge1" : {
      "source" : "int",
      "destination" : "int",
      "directed" : "true",
      "properties" : {
        "count" : "count"
      }
    }
  },
  "entities" : {
    "entity1" : {
      "vertex" : "int",
      "properties" : {
        "count" : "count"
      }
    },
    "entity" : {
      "description" : "test entity",
      "vertex" : "int",
      "properties" : {
        "count" : "count"
      }
    },
    "cardinality" : {
      "description" : "An entity that is added to every vertex representing the connectivity of the vertex.",
      "vertex" : "int",
      "properties" : {
        "edgeGroup" : "set",
        "hllp" : "hllp",
        "count" : "count"
      },
      "groupBy" : [ "edgeGroup" ]
    }
  },
  "types" : {
    "int" : {
      "class" : "java.lang.Integer",
      "aggregateFunction" : {
        "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Sum"
      }
    },
    "true" : {
      "class" : "java.lang.Boolean",
      "validateFunctions" : [ {
        "class" : "uk.gov.gchq.koryphe.impl.predicate.IsTrue"
      } ]
    },
    "count" : {
      "class" : "java.lang.Integer",
      "aggregateFunction" : {
        "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Sum"
      }
    },
    "set" : {
      "class" : "java.util.TreeSet",
      "aggregateFunction" : {
        "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.CollectionConcat"
      }
    },
    "hllp" : {
      "class" : "com.clearspring.analytics.stream.cardinality.HyperLogLogPlus",
      "aggregateFunction" : {
        "class" : "uk.gov.gchq.gaffer.sketches.clearspring.cardinality.binaryoperator.HyperLogLogPlusAggregator"
      },
      "serialiser" : {
        "class" : "uk.gov.gchq.gaffer.sketches.clearspring.cardinality.serialisation.HyperLogLogPlusSerialiser"
      }
    }
  }
}
Example getting compact schema

This operation will retrieve the compact Schema from the store, rather than the full schema.

final GetSchema operation = new GetSchema.Builder()
        .compact(true)
        .build();
{
  "class" : "GetSchema",
  "compact" : true
}
g.GetSchema(
  compact=True
)

Results:

{
  "edges" : {
    "edge" : {
      "source" : "int",
      "destination" : "int",
      "directed" : "true",
      "properties" : {
        "count" : "count"
      }
    },
    "edge1" : {
      "source" : "int",
      "destination" : "int",
      "directed" : "true",
      "properties" : {
        "count" : "count"
      }
    }
  },
  "entities" : {
    "entity1" : {
      "vertex" : "int",
      "properties" : {
        "count" : "count"
      }
    },
    "entity" : {
      "vertex" : "int",
      "properties" : {
        "count" : "count"
      }
    },
    "cardinality" : {
      "vertex" : "int",
      "properties" : {
        "edgeGroup" : "set",
        "hllp" : "hllp",
        "count" : "count"
      },
      "groupBy" : [ "edgeGroup" ]
    }
  },
  "types" : {
    "int" : {
      "class" : "Integer",
      "aggregateFunction" : {
        "class" : "Sum"
      }
    },
    "true" : {
      "class" : "Boolean",
      "validateFunctions" : [ {
        "class" : "IsTrue"
      } ]
    },
    "count" : {
      "class" : "Integer",
      "aggregateFunction" : {
        "class" : "Sum"
      },
      "serialiser" : {
        "class" : "OrderedIntegerSerialiser"
      }
    },
    "set" : {
      "class" : "TreeSet",
      "aggregateFunction" : {
        "class" : "CollectionConcat"
      },
      "serialiser" : {
        "class" : "TreeSetStringSerialiser"
      }
    },
    "hllp" : {
      "class" : "com.clearspring.analytics.stream.cardinality.HyperLogLogPlus",
      "aggregateFunction" : {
        "class" : "HyperLogLogPlusAggregator"
      },
      "serialiser" : {
        "class" : "HyperLogLogPlusSerialiser"
      }
    }
  },
  "vertexSerialiser" : {
    "class" : "OrderedIntegerSerialiser"
  }
}
{
  "edges" : {
    "edge" : {
      "source" : "int",
      "destination" : "int",
      "directed" : "true",
      "properties" : {
        "count" : "count"
      }
    },
    "edge1" : {
      "source" : "int",
      "destination" : "int",
      "directed" : "true",
      "properties" : {
        "count" : "count"
      }
    }
  },
  "entities" : {
    "entity1" : {
      "vertex" : "int",
      "properties" : {
        "count" : "count"
      }
    },
    "entity" : {
      "vertex" : "int",
      "properties" : {
        "count" : "count"
      }
    },
    "cardinality" : {
      "vertex" : "int",
      "properties" : {
        "edgeGroup" : "set",
        "hllp" : "hllp",
        "count" : "count"
      },
      "groupBy" : [ "edgeGroup" ]
    }
  },
  "types" : {
    "int" : {
      "class" : "java.lang.Integer",
      "aggregateFunction" : {
        "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Sum"
      }
    },
    "true" : {
      "class" : "java.lang.Boolean",
      "validateFunctions" : [ {
        "class" : "uk.gov.gchq.koryphe.impl.predicate.IsTrue"
      } ]
    },
    "count" : {
      "class" : "java.lang.Integer",
      "aggregateFunction" : {
        "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Sum"
      },
      "serialiser" : {
        "class" : "uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser"
      }
    },
    "set" : {
      "class" : "java.util.TreeSet",
      "aggregateFunction" : {
        "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.CollectionConcat"
      },
      "serialiser" : {
        "class" : "uk.gov.gchq.gaffer.serialisation.implementation.TreeSetStringSerialiser"
      }
    },
    "hllp" : {
      "class" : "com.clearspring.analytics.stream.cardinality.HyperLogLogPlus",
      "aggregateFunction" : {
        "class" : "uk.gov.gchq.gaffer.sketches.clearspring.cardinality.binaryoperator.HyperLogLogPlusAggregator"
      },
      "serialiser" : {
        "class" : "uk.gov.gchq.gaffer.sketches.clearspring.cardinality.serialisation.HyperLogLogPlusSerialiser"
      }
    }
  },
  "vertexSerialiser" : {
    "class" : "uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser"
  }
}

GetTraits

Gets the traits of the current store. Javadoc

Example getting all traits
final GetTraits operation = new GetTraits.Builder()
        .currentTraits(false)
        .build();
{
  "class" : "GetTraits",
  "currentTraits" : false
}
g.GetTraits(
  current_traits=False
)

Results:

QUERY_AGGREGATION
VISIBILITY
MATCHED_VERTEX
TRANSFORMATION
INGEST_AGGREGATION
PRE_AGGREGATION_FILTERING
POST_TRANSFORMATION_FILTERING
POST_AGGREGATION_FILTERING
[ "QUERY_AGGREGATION", "VISIBILITY", "MATCHED_VERTEX", "TRANSFORMATION", "INGEST_AGGREGATION", "PRE_AGGREGATION_FILTERING", "POST_TRANSFORMATION_FILTERING", "POST_AGGREGATION_FILTERING" ]
Example getting current traits

This will only return traits that are applicable to your current schema. This schema doesn't have a visibility property, so the VISIBILITY trait is not returned.

final GetTraits operation = new GetTraits.Builder()
        .currentTraits(true)
        .build();
{
  "class" : "GetTraits",
  "currentTraits" : true
}
g.GetTraits(
  current_traits=True
)

Results:

QUERY_AGGREGATION
MATCHED_VERTEX
TRANSFORMATION
INGEST_AGGREGATION
PRE_AGGREGATION_FILTERING
POST_TRANSFORMATION_FILTERING
POST_AGGREGATION_FILTERING
[ "QUERY_AGGREGATION", "MATCHED_VERTEX", "TRANSFORMATION", "INGEST_AGGREGATION", "PRE_AGGREGATION_FILTERING", "POST_TRANSFORMATION_FILTERING", "POST_AGGREGATION_FILTERING" ]

DeleteAllData

Deletes all retained data including deleting the graph. Javadoc

Note this operation does not return any response.

operationsDeclarations.json
{
    "operations": [
        {
            "operation": "uk.gov.gchq.gaffer.store.operation.DeleteAllData",
            "handler": {
                "class": "uk.gov.gchq.gaffer.accumulostore.operation.handler.DeleteAllDataHandler"
            }
        }
    ]
}
Example deleting all data
final DeleteAllData operation = new DeleteAllData()
{
  "class" : "DeleteAllData"
}
g.DeleteAllData()