subgraph

As its name suggests, the subgraph operations return a subpart of the graph. This operation returns the graph with vertices and edges that satisfy the user-defined criteria. In this example, we will fetch the subpart of the graph where the edge property is Friend.

The following is the signature of the subgraph method:

subgraph(scala.Function1<EdgeTriplet<VD,ED>,Object>   epred, scala.Function2<Object,VD,Object> vpred)   

The first parameter is used to filter the edges and the second parameter is used to filter vertices based on the user-defined criteria. As we want to filter the graph where the edge property is Friend, we do not need to specify any filter condition in the second parameter. The following is the implementation of both parameters:

public class AbsFunc1 extends AbstractFunction1<EdgeTriplet<string,string>, Object> implements Serializable {
@Override
public Object apply(EdgeTriplet<string, string> arg0) {
return arg0.attr().equals("Friend");
}
}
public class AbsFunc2 extends AbstractFunction2<Object, string, Object> implements Serializable {
@Override
public Object apply(Object arg0, string arg1) {
return true;
}
}

Hence, the subgraph operation can be executed as follows:

Graph<string, string> subgraph = graph.subgraph(new AbsFunc1(), new AbsFunc2());
subgraph.triplets().toJavaRDD().collect().forEach(System.out::println);

The logical output of the preceding operation on the graph is as follows:

Logical representation of output of the subgraph operation
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.17