如何在Windows 10的cmd外壳上的笔记本电脑上本地运行mapreduce程序

问题描述 投票:0回答:1

我正在尝试在笔记本电脑安装的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个回答
0
投票

该命令在任何Hadoop环境中均应相同。

FWIW,您可能应该切换到至少使用Pyspark

© www.soinside.com 2019 - 2024. All rights reserved.