【发布时间】:2020-12-24 16:11:25
【问题描述】:
我正在尝试使用自定义顶点类型创建一个简单的图形。创建成功,但顶点操作因 matchError 而失败。下面包含复制错误的步骤。
复制步骤(在 emr、spark-shell 上):
import org.apache.spark._
import org.apache.spark.graphx._
// To make some of the examples work we will also need RDD
import org.apache.spark.rdd.RDD
class VertexProperty() extends Serializable
case class UserProperty(val name: String) extends VertexProperty
case class ProductProperty(val name: String, val price: Double) extends VertexProperty
val u1 = new UserProperty("u1")
val u2 = new UserProperty("u2")
val p1 = new ProductProperty("p1", 1.0)
val p2 = new ProductProperty("p2", 2.0)
val users: RDD[(VertexId, VertexProperty)] = sc.parallelize(Seq( (1L, u1), (2L, u2) ))
val relationships: RDD[Edge[String]] = sc.parallelize(Seq(Edge(1L, 2L, "1-2") ))
val graph = Graph(users, relationships)
val c = graph.vertices.collect()
val d = c(0)._2
d match { case e: UserProperty => print(e.name)}
错误:
scala.MatchError: UserProperty(u1) (of class UserProperty)
... 53 elided
请立即指导我创建自定义类型或共享相同的文档。
【问题讨论】:
标签: scala apache-spark spark-graphx custom-type