【问题标题】:Passing result of mrjob step to next step as parameter将 mrjob 步骤的结果作为参数传递到下一步
【发布时间】:2015-05-09 08:49:46
【问题描述】:

我正在编写一个多步骤的 mrjob。第一步进行一些预处理,并以以下 reducer 结束:

def some_reducer(self, key, values):
    values = (int (value) for value in values)
    if key == 'iwantthiskey':
        //I want to pass sum(values) as a parameter to the next step

我尝试过阅读文档并尝试添加直通选项或向 self.jobconf() 添加值,但我无法弄清楚。 任何帮助将不胜感激。

【问题讨论】:

    标签: python mapreduce mrjob


    【解决方案1】:

    Sonic provided an excellent solution by making a global variable。基本上,一旦你得到想要的值,就将它存储在全局变量中以备后用。

    my_parameter = None
    
    def some_reducer(self, key, values):
      global my_parameter
      values = (int (value) for value in values)
      if key == 'iwantthiskey':
          my_parameter = sum(values)
    
    def next_funtion_or_job(self, input, parameter=my_parameter):
      #Your method goes here.
    

    ````

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-05
      • 2016-12-14
      • 1970-01-01
      • 2014-09-25
      • 1970-01-01
      • 2019-10-27
      相关资源
      最近更新 更多