首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在火花数据集上使用groupByKey中的最小/最大操作

在火花数据集上使用groupByKey中的最小/最大操作
EN

Stack Overflow用户
提问于 2019-07-23 18:37:45
回答 1查看 476关注 0票数 2

我正在尝试实现minmaxagg中的groupByKey操作。代码如下所示:

代码语言:javascript
运行
复制
import org.apache.spark.sql.functions._
import org.apache.spark.sql.TypedColumn
import org.apache.spark.sql.expressions.scalalang.typed.{
  count => typedCount, 
  sum => typedSum }

inputFlowRecords.groupByKey(inputFlowRecrd => inputFlowRecrd.FlowInformation)
  .agg(typedSum[InputFlowRecordV1](_.FlowStatistics.minFlowTime).name("minFlowTime"),
      typedSum[InputFlowRecordV1](_.FlowStatistics.maxFlowTime).name("maxFlowTime"),
      typedSum[InputFlowRecordV1](_.FlowStatistics.flowStartedCount).name("flowStartedCount"),
      typedSum[InputFlowRecordV1](_.FlowStatistics.flowEndedCount).name("flowEndedCount"),
      typedSum[InputFlowRecordV1](_.FlowStatistics.packetsCountFromSource).name("packetsCountFromSource"),
      typedSum[InputFlowRecordV1](_.FlowStatistics.bytesCountFromSource).name("bytesCountFromSource"),
      typedSum[InputFlowRecordV1](_.FlowStatistics.packetsCountFromDestination).name("packetsCountFromDestination"),
      typedSum[InputFlowRecordV1](_.FlowStatistics.bytesCountFromDestination).name("bytesCountFromDestination"))

我在这里面临两个问题:

  1. 与其求和,我想在少数列上取最小/最大值。当我尝试使用org.apache.spark.sql.functions.min/max操作时,错误说应该使用TypedColumns。如何解决这一问题?
  2. agg函数只允许我们指定最多4列。在其中,我有8列要聚合。如何才能做到这一点?
EN

回答 1

Stack Overflow用户

发布于 2019-07-23 19:58:55

不幸的是,似乎:

在您的例子中,一件合理的事情可能是定义您自己的专门聚合器来聚合InputFlowStatistics对象,所以您只有一个参数给agg

类型化聚合器是在这里定义的:typedaggregators.scala和Spark文档提供了一些关于创建自定义聚合器(->链接)的信息。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57170313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档