admin 管理员组

文章数量: 1086019


2024年3月13日发(作者:dubbo连接方式)

mapreduce java代码

以下是一个MapReduce的Java代码示例:

1. Map函数代码:

public static class Map extends Mapper

Text, IntWritable> 。

private Text word = new Text();。

private final static IntWritable one = new IntWritable(1);。

public void map(LongWritable key, Text value, Context

context) throws IOException, InterruptedException 。

String line = ng();。

StringTokenizer tokenizer = new StringTokenizer(line);。

while (eTokens()) 。

(ken());。

(word, one);。

}。

}。

}。

2. Reduce函数代码:

public static class Reduce extends Reducer

Text, IntWritable> 。

public void reduce(Text key, Iterable values,

Context context) throws IOException, InterruptedException 。

int sum = 0;。

for (IntWritable val : values) 。

sum += ();。

}。

(key, new IntWritable(sum));。

}。

}。

3. MapReduce主函数代码:

public static void main(String [] args) throws Exception 。

Configuration conf = new Configuration();。

Job job = new Job(conf, "wordcount");。

putKeyClass();。

putValueClass();。

perClass();。

ucerClass();。

utFormatClass();。

putFormatClass();。

utPath(job, new Path(args[0]));。

putPath(job, new Path(args[1]));。

}。


本文标签: 代码 函数 连接