【问题标题】:Pig SUM a column until it reaches a certain value and return the rowsPig SUM 一列,直到它达到某个值并返回行
【发布时间】:2015-04-27 21:24:27
【问题描述】:

有人可以帮我计算一个列的总和,直到它达到某个值。用例:产生 50% 收入的顶级产品。

有没有像piggybank这样的图书馆来完成它,我在piggybank中找不到。

我正在尝试实现 UDF,但我担心这是唯一的方法:(。

这是数据结构的样子-

productId、totalProfitByProduct、totalProfitByCompany、totalRevenueOfCompany。

totalProfitByProduct 上的数据按降序排列。 totalProfitByCompany、totalRevenueOfCompany 对于每一行都保持不变。

现在我想从顶部对上面的每个产品应用总和超过 totalProfitByProduct 并获得产生超过 50% 的 totalProfitByCompany 或 totalRevenueOfCompany 的顶级产品

【问题讨论】:

  • 通常你通过计算总和来做这样的事情,然后按总和 desc 排序,然后限制到前 10 名或其他任何东西。也许如果您将一些具有所需输出的示例输入数据添加到问题中,人们可以发布一些代码来帮助您。
  • 嘿伙计,这限制了行数。但我想限制总和。
  • 您能否发布一些示例数据以及您尝试过的内容?
  • 这里的数据结构看起来像 - productId、totalProfitByProduct、totalProfitByCompany、totalRevenueOfCompany。 totalProfitByProduct 上的数据按降序排列。 totalProfitByCompany、totalRevenueOfCompany 对于每一行都保持不变。现在我想从顶部对上面的每个产品应用总和超过 totalProfitByProduct 并获得产生 50% 的 totalProfitByCompany 或 totalRevenueOfCompany @mr2ert 的顶级产品

标签: hadoop apache-pig bigdata hadoop-plugins udf


【解决方案1】:

piggybank 有百分位 UDf,可用于您的要求。

Pig Script 连同 udf 可以帮助您实现它。

【讨论】:

    猜你喜欢
    • 2019-12-02
    • 1970-01-01
    • 2011-09-24
    • 2019-11-03
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 2020-11-13
    • 2011-10-16
    相关资源
    最近更新 更多