【问题标题】:How to average several columns at once in Scalding?如何在 Scalding 中一次平均几列?
【发布时间】:2013-03-26 17:38:15
【问题描述】:

作为使用 Scalding 进行某些计算的最后一步,我想计算管道中列的多个平均值。但是下面的代码不起作用

myPipe.groupAll { _average('col1,'col2, 'col3) }

有没有什么方法可以计算这些函数sum, max, average 而无需进行多次传递?我担心性能,但也许 Scalding 足够聪明,可以通过编程方式检测到这一点。

【问题讨论】:

    标签: hadoop cascading scalding


    【解决方案1】:

    此问题已在cascading-user 论坛中得到解答。在这里留下答案作为参考

    myPipe.groupAll { _.average('col1).average('col2).average('col3) }
    

    【讨论】:

    • 如果你想在一行中使用圆括号。 myPipe.groupAll(_.average('col1).average('col2).average('col3))。花括号应该扩展到 3 行。
    • @ancehu 如何在 Cascading 中实现?
    【解决方案2】:

    您可以使用以下函数一次性完成大小(也称为计数)、平均值和标准开发。

    // Find the count of boys vs. girls, their mean age and standard deviation. 
    // The new pipe contains "sex", "count", "meanAge" and "stdevAge" fields.
    val demographics = people.groupBy('sex) { _.sizeAveStdev('age -> ('count, 'meanAge, 'stdevAge) ) }
    

    不过,要找到最大值需要再通过一次。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 2020-03-07
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      相关资源
      最近更新 更多