python - Hadoop Streaming "comparator.options"未被尊重

标签 python hadoop mapreduce streaming bigdata

我有一个 python 映射器和缩减器,我正在使用它和 Hadoop 流式 API。 在命令行上,这些脚本可以正常工作并执行预期的工作。

我有一个 NASA 网络访问日志示例,您可以在此处看到它已正确处理和排序。

tail -n 10 NASA_access_log_Jul95  | ./mapper.py | sort | ./reducer.py | sort -r -k1,1
4   163.205.53.14
1   tornado.umd.edu

在 map reduce 作业中尝试相同的操作时,排序没有得到遵守。

hadoop jar /usr/lib/hadoop-0.20-mapreduce/contrib/streaming/hadoop-streaming-2.0.0-mr1-cdh4.4.0.jar 
-D mapred.output.key.comparator.class=org.apache.hadoop.mapred.lib.KeyFieldBasedComparator     
-D mapred.text.key.comparator.options=-rk1,1
-file mapper.py -mapper mapper.py 
-file reducer.py -reducer reducer.py 
-input /user/cloudera/logcount/input 
-output /user/cloudera/logcount/output

具体参数: ma​​pred.text.key.comparator.options=-rk1,1

作业的最终结果是:

 hadoop fs -cat /user/cloudera/logcount/output/part-00000 | more
 16 ***.novo.dk
 32735  /
 161    /"
 1  /%20%20history/apollo/apollo-13/apollo-13.html
 4  /%20history/apollo/apollo-13/apollo-13.html

它对值进行了排序,而不是我想要的键。 我也试过去掉 'r' 但没有效果。

如果不清楚,我将尝试按点击次数/观看次数(第一列)降序排列结果。

感谢任何帮助! TIA。

最佳答案

您正在尝试对 reducer 而不是 mapper 的输出进行排序。请注意排序阶段发生在 map 和 reduce 之间,这意味着 mapred.text.key.comparator.options 用于对 mapper 的输出进行排序。所以我猜你有 2 个选择:

  1. 重写mapper和reducer,将reducer的工作集成到mapper中,reducer什么都不做。
  2. 在这个 mapreduce 作业之后创建另一个 mapreduce 作业以按计数对输出进行排序。

关于python - Hadoop Streaming "comparator.options"未被尊重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20802243/

相关文章:

hadoop - 将数据从 Hadoop 传输到 Google Cloud Storage 时如何加快 distcp 速度

hadoop - 使用 Mapreduce 计算期望最大化的高斯混合模型

hadoop - 为什么 MapReduce 作业没有完全加载附加文件?

python - 元类可以有方法吗?

python - Django 表单 : could not convert string to float

python - 在python中解析xml - 不理解DOM

xml - 解析数百万个小 XML 文件

Python 字符串 LCS 错误

java - 无法将 Java 客户端连接到远程计算机中的独立 HBase 设置

hadoop - Hadoop作业配置