【问题标题】:How to deactivate output in Hadoop streaming?如何停用 Hadoop 流中的输出?
【发布时间】:2015-03-29 21:57:48
【问题描述】:

我正在我的集群上编写 Python mapreduce 程序。我的映射器解析数据并将它们存储在 HBase 中。没有减速器,没有输出。

如果需要,下面是代码供参考。

class Mapper:
  ...
  def __init__(...)
     ...

  def start(self, file):
    generator = self.read_input(file)
    connection = happybase.Connection(Mapper.IP)
    self.table = connection.table(Mapper.table_name)
    for line in generator:
      self.parse(line)
      self.write()
      self.buffers = []
    self.table = None
    connection.close()

  def read_input(self, file):
    ...
  def parse(self, line):
    ...
  def write(self):
    # write buffers into HBase
    for cell in self.buffers:
      self.table.put(cell[0], cell[1])     <-  Into HBase yay

我的问题是:如果我在集群中使用这个命令:

bin/hadoop jar contrib/streaming/hadoop-*streaming*.jar \
-D mapred.reduce.tasks=1 \
-file /home/hduser/mapper.py    -mapper /home/hduser/mapper.py \
-input /user/hduser/streamingTest/testFile.csv    

它会说:oops, ERROR streaming.StreamJob: Missing required option: output

我可以将输出重定向到标准输出,或者完全停用它吗?

PS:我是一个糟糕的python程序员,任何让你不舒服的代码请指出。

【问题讨论】:

    标签: python mapreduce hbase hadoop-streaming


    【解决方案1】:

    您将需要生成一些输出。鉴于不想输出任何东西,请使用

    NullOutputFormat
    

    如下:

    ---outputformat org.apache.mapreduce.lib.NullOutputFormat
    

    【讨论】:

    • 如何将输出重定向到屏幕,这可能吗?因为我的映射器每小时运行一次,而不是一次。输出到文件会产生大量的文件。
    • 嗨@javadba 我认为脚本完成后,python 会自动处理任何连接,也许?我向你学习。
    • @Vindicate 可能是这种情况,但明确关闭连接是更好的做法/更安全。
    • 有效!谢谢!我想你可能想删除特定的 NullOutputFormat 位置,它似乎从版本到版本。
    • 你介意我修改我的代码以添加 disconnection() 吗?那么你的答案就只有两行了,酷!
    猜你喜欢
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    相关资源
    最近更新 更多