【问题标题】:how to change ouput format of mapreduce in hadoop?如何在hadoop中更改mapreduce的输出格式?
【发布时间】:2017-03-28 18:32:04
【问题描述】:

我现在正在 Hadoop 中练习 MapReduce, 我得到了这个矩阵乘法的代码, 运行它没有任何问题,但output format 不是我想要的。我目前有:

00    66
01    78
02    90

我想要的格式是这样的

0,0,66
0,1,78
0,2,90

如何更改code?

【问题讨论】:

  • 您需要更改键格式并添加逗号并查看此答案以更改键/值之间的分隔符 - stackoverflow.com/questions/11031785/…
  • @BinaryNerd 实际上我只是找不到更改密钥格式的位置...,我尝试了 mapred.textoutputformat.separator", "," , mapreduce.textoutputformat.separator", " ", 和 mapreduce.output.textoutputformat.separator", ",",但它们都不起作用。
  • 所以你修复了分隔符,它只是现在问题所在的关键?
  • @BinaryNerd 不,分隔符也不固定,也许我应该尝试 conf.set("mapreduce.output.key.field.separator", separator); conf.set("mapred.textoutputformat.separatorText", 分隔符);看看它是否可以修复它 p.s.我的 hadoop 版本。是 2.6
  • 您需要将conf.set("mapreduce.textoutputformat.separator", ","); 添加到您的主目录中,如我链接到的答案中所述。

标签: hadoop mapreduce format matrix-multiplication


【解决方案1】:

您可以在 Mapper 中更改密钥的格式。它在两个地方创建sKey。目前两条线(56 和 68)看起来像:

sKey = row+i; (taking line 56 as an example)

所以你也可以改变它:

sKey = row+","+i;

这将为您提供所需的格式。

【讨论】:

  • 我也是 1 小时前才知道的。非常感谢你!
猜你喜欢
  • 2020-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-05
  • 2022-01-21
相关资源
最近更新 更多