scala - 迭代数据框时任务不可序列化,scala
问题描述
下面是我的代码,当我尝试遍历每一行时:
val df: DataFrame = sqlContext.read
.format("com.databricks.spark.csv")
.option("header", true) // Use first line of all files as header
.option("delimiter", TILDE)
.option("inferSchema", "true") // Automatically infer data types
.load(fileName._2)
val accGrpCountsIds: DataFrame = df.groupBy("accgrpid").count()
LOGGER.info(s"DataFrame Count - ${accGrpCountsIds.count()}")
accGrpCountsIds.show(3)
//switch based on file names and update the model.
accGrpCountsIds.foreach(accGrpRow => {
val accGrpId = accGrpRow.getLong(0)
val rowCount = accGrpRow.getInt(1)
}
当我尝试使用上面的数据框进行交互时foreach
,我得到一个任务不可序列化错误。我怎样才能做到这一点?
解决方案
您的 foreach 中是否还有其他未共享的类型?或者这就是你所做的一切,但它不起作用?
accGrpCountsIds.foreach(accGrpRow => {
val accGrpId = accGrpRow.getLong(0)
val rowCount = accGrpRow.getInt(1)
}
另外,您可能会觉得这有用吗? 任务不可序列化:java.io.NotSerializableException 仅在类而非对象上调用闭包外的函数时
推荐阅读
- groovy - 如何在 jmeter 发布请求中发送 id 数组(存储在 csv 中)
- python - 我可以在带有硒的a标签下用python获取b标签中的数据吗?
- python - Python计算文件中同一行上的多个匹配字符串
- python - Heroku 与 Django、Celery 和 CloudAMPQ - 超时错误
- swift - 如何以通用格式编写可编码
- php - 使用 php 在 AWS QLDB 中提交事务时如何获取/计算 CommitDigest?
- php - 我们如何使用 PHP Wordpress 从后端启用和禁用必填字段属性
- azure - 比较两个 Azure 函数应用的应用程序设置
- swift - 如何从特定索引的字符串中快速删除某个长度的子字符串
- python - 包含某些元组的元组的元组索引列表