Java Code Examples for org.apache.spark.graphx.Graph#apply()
The following examples show how to use
org.apache.spark.graphx.Graph#apply() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphXGraphGenerator.java From rya with Apache License 2.0 | 8 votes |
public Graph<RyaTypeWritable, RyaTypeWritable> createGraph(SparkContext sc, Configuration conf) throws IOException, AccumuloSecurityException{ StorageLevel storageLvl1 = StorageLevel.MEMORY_ONLY(); StorageLevel storageLvl2 = StorageLevel.MEMORY_ONLY(); ClassTag<RyaTypeWritable> RTWTag = ClassTag$.MODULE$.apply(RyaTypeWritable.class); RyaTypeWritable rtw = null; RDD<Tuple2<Object, RyaTypeWritable>> vertexRDD = getVertexRDD(sc, conf); RDD<Tuple2<Object, Edge>> edgeRDD = getEdgeRDD(sc, conf); JavaRDD<Tuple2<Object, Edge>> jrddTuple = edgeRDD.toJavaRDD(); JavaRDD<Edge<RyaTypeWritable>> jrdd = jrddTuple.map(tuple -> tuple._2); RDD<Edge<RyaTypeWritable>> goodERDD = JavaRDD.toRDD(jrdd); return Graph.apply(vertexRDD, goodERDD, rtw, storageLvl1, storageLvl2, RTWTag, RTWTag); }
Example 2
Source File: SparkGraphXKickoff.java From -Data-Stream-Development-with-Apache-Spark-Kafka-and-Spring-Boot with MIT License | 4 votes |
public static void main(String[] args) throws InterruptedException { System.setProperty("hadoop.home.dir", HADOOP_HOME_DIR_VALUE); final SparkConf conf = new SparkConf() .setMaster(RUN_LOCAL_WITH_AVAILABLE_CORES) .setAppName(APPLICATION_NAME); JavaSparkContext javaSparkContext = new JavaSparkContext(conf); List<Tuple2<Object, String>> listOfVertex = new ArrayList<>(); listOfVertex.add(new Tuple2<>(1l, "James")); listOfVertex.add(new Tuple2<>(2l, "Andy")); listOfVertex.add(new Tuple2<>(3l, "Ed")); listOfVertex.add(new Tuple2<>(4l, "Roger")); listOfVertex.add(new Tuple2<>(5l, "Tony")); List<Edge<String>> listOfEdge = new ArrayList<>(); listOfEdge.add(new Edge<>(2, 1, "Friend")); listOfEdge.add(new Edge<>(3, 1, "Friend")); listOfEdge.add(new Edge<>(3, 2, "Colleague")); listOfEdge.add(new Edge<>(3, 5, "Partner")); listOfEdge.add(new Edge<>(4, 3, "Boss")); listOfEdge.add(new Edge<>(5, 2, "Partner")); JavaRDD<Tuple2<Object, String>> vertexRDD = javaSparkContext.parallelize(listOfVertex); JavaRDD<Edge<String>> edgeRDD = javaSparkContext.parallelize(listOfEdge); ClassTag<String> stringTag = scala.reflect.ClassTag$.MODULE$.apply(String.class); Graph<String, String> graph = Graph.apply( vertexRDD.rdd(), edgeRDD.rdd(), "", StorageLevel.MEMORY_ONLY(), StorageLevel.MEMORY_ONLY(), stringTag, stringTag ); //apply specific algorithms, such as PageRank graph.vertices() .saveAsTextFile(VERTICES_FOLDER_PATH); graph.edges() .saveAsTextFile(EDGES_FOLDER_PATH); javaSparkContext.close(); }