java—如何在Hadoop2中连接context.write()的字符串和值

mtb9vblg  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(325)

我在使用hadoop v2的这个减速机上的输出遇到了一些问题
出于某种原因,如果我尝试将string.valueof(pagerank)连接到字符串上,则更新的值不会写入输出。而是为每个值写入值0.15。有人能帮我吗?如果需要的话,我会提供更多的信息。谢谢!

  1. static class LoopingPRReducer extends Reducer<Text, Text, Text, Text> {
  2. // The main reduce() function; the input key/value classes must match the first two above, and the key/value classes in your emit() statement must match the latter two above.
  3. // Make sure that the output key/value classes also match those set in your job's configuration (see below).
  4. @Override
  5. protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
  6. String outlinks = null;
  7. double sum = 0.0;
  8. for (Text value: values) {
  9. String rank = value.toString();
  10. if (rank.contains("[")) {
  11. outlinks = rank;
  12. continue;
  13. }
  14. sum += Double.parseDouble(rank);
  15. }
  16. double pageRank = (sum)*0.85+0.15;
  17. String newRank = "[" + String.valueOf(pageRank)+"]"; //formatted output doesn't work
  18. context.write(key, new Text(newRank));}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题