-
Notifications
You must be signed in to change notification settings - Fork 88
Binary Logical Graph Operators
This section provides an overview of binary graph operators, which consume two graphs as input.
Binary Logical Graph Operators |
---|
Combination |
Overlap |
Exclusion |
Equality |
VertexFusion |
Given two graphs, the combine operator creates a LogicalGraph
that includes the edges and vertices of both graphs.
It is implemented by the combine()
function of the LogicalGraph
. The combine function takes a LogicalGraph
as its input and outputs a new
LogicalGraph
that includes the elements of both graphs.
Consider the social graph from our quickstart section.
We use the combine function to retrieve all Person older than 30 of both graphs.
// Combine both graphs
LogicalGraph combination = n1.combine(n2)
// Retrieve the persons that are older than 30
.subgraph(
v -> v.getLabel().equals("Person") && v.getPropertyValue("age").getInt() >= 30,
e -> false
);
Given two graphs, the overlap operator extracts their common vertices and edges resulting in a new LogicalGraph
.
It is implemented by the overlap()
function of the LogicalGraph
. The overlap function takes a LogicalGraph
as its input and outputs a new
LogicalGraph
consisting of the common elements in both graphs.
Consider the social graph from our quickstart section.
We use the overlap function to retrieve the common elements in both graphs.
LogicalGraph overlap = n2.overlap(n1);
Given two graphs a and b, the exclusion operator creates a LogicalGraph
that includes the edges and vertices of graph a that do not occur in graph b.
It is implemented by the exclude()
function of the LogicalGraph
. The exclude function takes a LogicalGraph
as its input and outputs a new
LogicalGraph
consisting of the elemtents of graph a without the elements of graph b.
Consider the social graph from our quickstart section.
We use the exclude function to retrieve all elements from graph n1 that do not occur in n2.
LogicalGraph exlusion = n1.exclude(n2);
Given two graphs, the equality operator determines whether they are equal.
The operator is implemented by the LogicalGraph
. The equal operator takes another LogicalGraph
as its input and outputs a DataSet<Boolean>
that contains a single boolean value.
Method | Description |
---|---|
equalsByData | Compares the vertices, edges, graph label and the graph properties of the LogicalGraphs for equality. |
equalsByElementData | Compares only vertices and edges of the LogicalGraphs for equality. |
equalsByElementIds | Compares the vertices and edges of the LogicalGraphs for equality by using their internal ID. Therefore, 2 graphs may have vertices and edges with the same properties without being equal. |
DataSet<Boolean> equal = n1.equals(n2);
The vertex fusion operator searches for a pattern graph inside a graph and fuses the whole pattern into a single vertex. An empty search graph always results into an empty graph, while an empty pattern graph always returns the whole search graph. The old edges originating from a vertex in the pattern start from the fused vertex and edges that pointed to a vertex in the pattern point to the fused vertex as well. Edges between vertices in the pattern graph, therefore, result in a loop on the fused vertex.
Consider the social graph from the quickstart example. Lets assume that the two companies are forming a merger and we want to fuse both vertices.
FlinkAsciiGraphLoader loader = ...;
String patterngraphDefinition =
"sg1:patterngraph[" +
"(c1:Company {name: \"Acme Corp\"})" +
"(c2:Company {name: \"Globex Inc.\"})" +
"]";
loader.initDatabaseFromString(patterngraphDefinition);
LogicalGraph searchGraph = n1;
LogicalGraph patternGraph = loader.getLogicalGraphByVariable("sg1");
LogicalGraph fusedGraph = new VertexFusion().execute(searchGraph, patternGraph);
This operation results in the following graph:
g0:graph [
(v_Person_0:Person {name:"Bob",age:24})
(v_Person_1:Person {name:"Jacob",age:27})
(v_Person_2:Person {name:"Sara",age:33})
(v_patterngraph_3:patterngraph )
(v_Person_4:Person {name:"Marc",age:40})
(v_Person_5:Person {name:"Alice",age:30})
(v_Person_2)-[e_friendsWith_0:friendsWith]->(v_Person_4)
(v_Person_4)-[e_worksAt_1:worksAt]->(v_patterngraph_3)
(v_Person_5)-[e_friendsWith_2:friendsWith]->(v_Person_0)
(v_Person_4)-[e_friendsWith_3:friendsWith]->(v_Person_1)
(v_Person_2)-[e_worksAt_4:worksAt]->(v_patterngraph_3)
(v_Person_0)-[e_friendsWith_5:friendsWith]->(v_Person_5)
(v_Person_1)-[e_friendsWith_6:friendsWith]->(v_Person_4)
(v_Person_4)-[e_friendsWith_7:friendsWith]->(v_Person_2)
(v_Person_0)-[e_worksAt_8:worksAt]->(v_patterngraph_3)
(v_Person_5)-[e_friendsWith_9:friendsWith]->(v_Person_1)
(v_Person_1)-[e_friendsWith_10:friendsWith]->(v_Person_5)
(v_Person_5)-[e_worksAt_11:worksAt]->(v_patterngraph_3)
(v_Person_1)-[e_worksAt_12:worksAt]->(v_patterngraph_3)
]