【问题标题】:How to Run mapreduce Program locally on laptop on cmd shell in windows 10如何在 Windows 10 的 cmd shell 上的笔记本电脑上本地运行 mapreduce 程序
【发布时间】:2020-01-15 11:17:10
【问题描述】:

我正在尝试在安装 hadoop 2.8 版本的笔记本电脑上本地运行 MapReduce 程序。我很困惑如何在 Cmd shell 中使用下面的命令。

这是我的命令,也共享映射器和减速器代码。以及我在 CSV 文件中的数据。

D:\hadoop\bin\hadoop jar D:\hadoop\share\hadoop\tools\lib\hadoop-streaming-2.3.0.jar 
-D mapred.reduce.tasks=0
-file /reducer.py -mapper "mapper.py" 
-input /data2.csv -input /data2.csv 
-output /output
#!/usr/bin/python3
#mapper.py
import sys

# input comes from STDIN (standard input)
for line in sys.stdin:
    line = line.strip()
    line = line.split(",")

    if len(line) >=2:
        sex = line[1]
        age = line[2]
        print ('%s\t%s' % (sex, age))
#!/usr/bin/python3
#Reducer.py
import sys

sex_age = {}

#Partitoner
for line in sys.stdin:
    line = line.strip()
    sex, age = line.split('\t')

    if sex in sex_age:
        sex_age[sex].append(int(age))
    else:
        sex_age[sex] = []
        sex_age[sex].append(int(age))

#Reducer
for sex in sex_age.keys():
    ave_age = sum(sex_age[sex])*1.0 / len(sex_age[sex])
    print ('%s\t%s'% (sex, ave_age))

【问题讨论】:

    标签: python hadoop mapreduce hadoop-streaming


    【解决方案1】:

    该命令应该在任何 Hadoop 环境中都可以正常工作。

    FWIW,你应该至少改用 Pyspark

    【讨论】:

      猜你喜欢
      • 2022-08-18
      • 2012-12-30
      • 1970-01-01
      • 2021-03-02
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      相关资源
      最近更新 更多