java (mapreduce)

一、java mapreduce实现

数据块

1950,0

1950,22

1950,-11

1949,111

1949,78

例如:(1950,0),(1950,22),(1950,-11),(1949,111),(1949,78) 求每年的最大值

伪代码

map函数

public void map(LongWritable key,Text value,Context context)

{

           String line = value.toStirng();

           

            context.write(year,value)

}

reduce 函数

pubilc void reduce(Text key,values,context){

year = key                 

for (value :values){

                         maxvalue= max(value)

                  } 

 context.write(year,maxvalue) 返回每年的最大值

}

main 方法

new job

 map.class

reduce.class 

猜你喜欢

转载自kayak2015.iteye.com/blog/2288062