2014-02-09 02:13:34 -05:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership.
|
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
* (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main.scala
|
|
|
|
|
2014-04-21 13:26:33 -04:00
|
|
|
import org.apache.spark.{SparkContext, SparkConf}
|
2014-02-09 02:13:34 -05:00
|
|
|
import org.apache.spark.SparkContext._
|
|
|
|
import org.apache.spark.graphx._
|
|
|
|
import org.apache.spark.rdd.RDD
|
|
|
|
|
|
|
|
object GraphXApp {
|
|
|
|
def main(args: Array[String]) {
|
2014-04-21 13:26:33 -04:00
|
|
|
val conf = sys.env.get("SPARK_AUDIT_MASTER") match {
|
|
|
|
case Some(master) => new SparkConf().setAppName("Simple GraphX App").setMaster(master)
|
|
|
|
case None => new SparkConf().setAppName("Simple Graphx App")
|
|
|
|
}
|
|
|
|
val sc = new SparkContext(conf)
|
|
|
|
SparkContext.jarOfClass(this.getClass).foreach(sc.addJar)
|
|
|
|
|
2014-02-09 02:13:34 -05:00
|
|
|
val users: RDD[(VertexId, (String, String))] =
|
|
|
|
sc.parallelize(Array((3L, ("rxin", "student")), (7L, ("jgonzal", "postdoc")),
|
|
|
|
(5L, ("franklin", "prof")), (2L, ("istoica", "prof")),
|
|
|
|
(4L, ("peter", "student"))))
|
|
|
|
val relationships: RDD[Edge[String]] =
|
|
|
|
sc.parallelize(Array(Edge(3L, 7L, "collab"), Edge(5L, 3L, "advisor"),
|
|
|
|
Edge(2L, 5L, "colleague"), Edge(5L, 7L, "pi"),
|
|
|
|
Edge(4L, 0L, "student"), Edge(5L, 0L, "colleague")))
|
|
|
|
val defaultUser = ("John Doe", "Missing")
|
|
|
|
val graph = Graph(users, relationships, defaultUser)
|
|
|
|
// Notice that there is a user 0 (for which we have no information) connected to users
|
|
|
|
// 4 (peter) and 5 (franklin).
|
|
|
|
val triplets = graph.triplets.map(e => (e.srcAttr._1, e.dstAttr._1)).collect
|
|
|
|
if (!triplets.exists(_ == ("peter", "John Doe"))) {
|
|
|
|
println("Failed to run GraphX")
|
|
|
|
System.exit(-1)
|
|
|
|
}
|
|
|
|
println("Test succeeded")
|
|
|
|
}
|
|
|
|
}
|