scala - Spark 2.0-2.3 数据集 groupByKey 和 mapGroups
问题描述
当我在本地运行时,我看到了正确的记录输出。但是,当我在集群上运行时,输出是不同的,并且看起来不一致。甚至某些 mappedGroup 输出也是正确的。这是火花闭包的问题吗?不知道如何最好地描述我所看到的。
我可能不理解 mapGroups 并且并非每个组的所有值都进入 recordList 变量。
case class MyCaseClass (keyValue: int,c2: String,c3: String,c4: Double)
case class NewClass (thing1:String,thing2:String,thing3:String,thing4:String)
case class WorkTodo(myClassRecords: Seq[MyCaseClass]){
def toNewRecords: Seq[NewClass] = {
//e.g. work that requires all MyCaseClass.keyValue=1 to be in the list.
//This function would create new Java Objects to perform calculations and eventually output a set of NewClass records
}
val processedRecords = ds.as[MyCaseClass].groupByKey(_.keyValue)
.mapGroups {
case (v, iter) => {
var recordList = new ListBuffer[MyCaseClass]
iter.foreach {x=>
recordList += MyCaseClass(x.keyValue,x.c2,x.c3,x.c4)
}
WorkToDo(recordList).toNewRecords
}
}
PS 欢迎任何其他仍然使用数据集的解决方案:)
解决方案
推荐阅读
- python-3.x - 如何使用 Python 调用 add-iam-policy-binding?
- javascript - 快速路线不起作用
- python - 使用 mysql-connector-python 实现线程安全的最有效方法是什么?
- amazon-web-services - 满足我要求的最佳 AWS RDS 实例
- python - 如何在pyqt5中获得切换值?
- android - Android Composable Text 在接收到 Color 参数时会中断预览。有解决方法吗?
- javascript - 如何调试和检查递归函数?
- aws-amplify - 是否可以延长用户更改密码和设置个人资料的时间?
- sql - 如何将字符字符串转换为 uniqueidentifier 并使用 Stuff 函数?
- javascript - 如何在 css 中定义多转换属性?