Skip to content

Binary Graph Collection Operators

Timo edited this page Aug 1, 2018 · 3 revisions

This section provides an overview of binary graph collection operators, which consume two GraphCollections as input.

Binary Graph Collection Operators
Union
Intersection
Difference
Equality

Union

Given two collections, the union operator creates a GraphCollection that includes all logical graphs of both input collections. Graph equality is based on their identifiers.

Method Description
union Returns the union of both GraphCollections.

Union example

Consider the Social Network example graph, which contains multiple logical graphs with different relations. This example takes two graph collections with different logical graphs from the social network graph and creates the union of both.

FlinkAsciiGraphLoader loader = getSocialNetworkLoader();

GraphCollection col02 = loader.getGraphCollectionByVariables("g0", "g2");
GraphCollection col12 = loader.getGraphCollectionByVariables("g1", "g2");

GraphCollection result = col02.union(col12); // g0, g1, g2

result now contains the logical graphs g0, g1 and g2.

Intersection

Given two collections, the intersection operator creates a GraphCollection that includes all logical graphs that exist in both input collections. Graph equality is based on their identifiers.

Method Description
intersect Returns the intersection of both GraphCollections.
intersectWithSmallResult Returns the intersection of both GraphCollections. Alternate implementation that works faster if the other GraphCollection is small (e.g. fits in the workers main memory).

Intersection example

Consider the Social Network example graph, which contains multiple logical graphs with different relations. This example takes two graph collections with different logical graphs from the social network graph and creates the intersection of both.

FlinkAsciiGraphLoader loader = getSocialNetworkLoader();

GraphCollection col02 = loader.getGraphCollectionByVariables("g0", "g2");
GraphCollection col12 = loader.getGraphCollectionByVariables("g1", "g2");

GraphCollection result = col02.intersect(col12); // g2

result now contains the logical graph g2.

Difference

Given two collections, the difference operator creates a GraphCollection that includes all logical graphs that are contained in that collection but not in the other. Graph equality is based on their identifiers.

Method Description
difference Returns the difference of both GraphCollections.
differenceWithSmallResult Returns the difference of both GraphCollections. Alternate implementation that works faster if the intermediate result (list of graph identifiers) is small (e.g. fits in the workers main memory).

Difference example

Consider the Social Network example graph. This graph contains multiple logical graphs with different relations. This example takes two graph collections with different logical graphs from the social network graph and creates the difference of both.

FlinkAsciiGraphLoader loader = getSocialNetworkLoader();

GraphCollection col02 = loader.getGraphCollectionByVariables("g0", "g2");
GraphCollection col12 = loader.getGraphCollectionByVariables("g1", "g2");

GraphCollection result = col02.difference(col12); // g0

result now contains the logical graph g0.

Equality

Given two collections, the equality operator determines whether they are equal. The operator is implemented by the GraphCollection. The equality operator takes another GraphCollection as its input and outputs a DataSet<Boolean> that contains a single boolean value.

Method Description
equalsByGraphIds Compares IDs of the graph heads of the GraphCollections for equality.
equalsByGraphElementIds Compares IDs of the vertices and edges of the GraphCollections for equality.
equalsByGraphElementData Compares data of the vertices and edges of the GraphCollections for equality.
equalsByGraphData Compares data of the vertices, edges and graph heads of the GraphCollections for equality.

Equality example

Consider the Social Network example graph. This graph contains multiple logical graphs with different relations. This example takes two graph collections from the social network graph and checks for equality.

FlinkAsciiGraphLoader loader = getSocialNetworkLoader();

GraphCollection col1 = loader.getGraphCollectionByVariables("g0", "g1");
GraphCollection col2 = loader.getGraphCollectionByVariables("g0", "g1");

DataSet<Boolean> result = col1.equalsByGraphElementData(col2);

boolean equal = result.collect().get(0); // true

result is a DataSet<Boolean> that contains true.