apache-spark - 具有多种功能的 GraphX 边
问题描述
我正在使用 Graphx 并尝试向边缘添加功能。我有一个带有 Id1、Id2、重量、类型的 csv 文件
我能够获得 ID 和一个功能 - 重量或类型。有没有办法为一条边保存多个特征。这是我的代码片段:
val edgesWriterWriterCollaborated: RDD[Edge[String]] = sc.textFile(edgeWeightedWriterWriterCollaborated).map {
line =>
val row = line.split(",")
Edge(row(0).toLong, row(1).toLong, row(2))
}
这给了我一个错误:
val edgesWriterWriterCollaborated: RDD[Edge[Tuple2]] = sc.textFile(edgeWeightedWriterWriterCollaborated).map {
line =>
val row = line.split(",")
Edge(row(0).toLong, row(1).toLong, (row(2), row(3)))
}
更新:
我这样修复了我的代码:
case class WriterWriterProperties(weight: String, edgeType: String)
val edgesWriterWriterCollaborated: RDD[Edge[WriterWriterProperties]] = sc.textFile(edgeWeightedWriterWriterCollaborated).map {
line =>
val row = line.split(",")
Edge(row(0).toLong, row(1).toLong, WriterWriterProperties(row(2), row(3)))
}
但是,当我尝试打印时:
graph4.triplets.foreach(println)
我收到一个错误:Caused by: java.io.NotSerializableException
解决方案
当然。使用Tuple2
:
Edge(row(0).toLong, row(1).toLong, (row(2), row(3)))
或在您的情况下有意义的任何特定于域的对象:
case class FooBar(foo: String, bar: String)
Edge(row(0).toLong, row(1).toLong, FooBar(row(2), row(3)))
推荐阅读
- java - 如何使用 Maven 在 Heroku 上运行测试
- python - Pandas 根据条件在多列中找到第一个非零条目
- angular - 带有 @Input() 的 Angular ExpressionChangedAfterItHasBeenCheckedError 到子视图
- android - 无法从 Android 模拟器客户端中的 python 服务器接收数据
- html - 带有 contenteditable 的 Chrome 错误和带有 display:flex 的列表
- python - 根据时间戳合并数据框中的行
- python - Python mysql参数和加载数据命令
- react-native - 当 RN 0.61 中的状态发生变化时,如何从主组件重新渲染子组件?
- terraform - 在 terraform V0.12 中连接变量
- jquery - 单击功能上的 Ajax - 不响应按钮