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'
{
"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
}
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.
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
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.
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
Results:
CountGroups
Counts the different element groups. Javadoc
Example counting all element groups
Results:
Example counting all element groups with limit
Results:
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
}
} ]
}
} ]
}
Results:
[ {
"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
}
} ]
}
}
} ]
}
Results:
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
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.
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.
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
} ]
} ]
}
Results:
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:
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
} ]
} ]
}
Results:
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:
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
} ]
}
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
} ]
}
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"
}
} ]
}
} ]
}
Results:
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();
Results:
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:
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
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
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:
ToEntitySeeds
Converts object(s) into EntitySeeds. Javadoc
Example 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
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" : { }
}
} ]
}
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
} ]
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
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
Results:
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"
} ]
}
} ]
}
Results:
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
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]]
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"
} ]
}
Results:
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:
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"
} ]
}
Results:
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:
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:
GetGraphCreatedTime
Gets the creation date of the current graph. Javadoc
Example getting the graph created time
Results:
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.
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.
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
Results:
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.
Results:
DeleteAllData
Deletes all retained data including deleting the graph. Javadoc
Note this operation does not return any response.