我想從MapReduce運行MaxTemperature示例。但是我無法在Hadoop MapReduce示例中找到MaxTemperature.jar。有人可以幫我找到jar文件或者執行這個程序的可能性,看看輸出結果是什麼?Hadoop上的MapReduce的MaxTemperature示例
0
A
回答
0
試試這個,這個方案的
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class Temp {
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
// private final static IntWritable one = new IntWritable();
// private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException InterruptedException
{
String line = value.toString();
String year=line.substring(0,4);
//StringTokenizer tokenizer = new StringTokenizer(line);
// while (tokenizer.hasMoreTokens()) {
// word.set(tokenizer.nextToken());
// output.collect(word, one);
int Temp=Integer.parseInt(line.substring(6,8));
context.write(new Text(year),new IntWritable(Temp));
}
}
}
/*
public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
// int max=Integer.MIN_VALUE;
int sum=0;
while (values.hasNext()) {
sum += values.next().get();
}
output.collect(key, new IntWritable(sum));
}
}*/
public class Reduce extends Reducer<Text, IntWritable, Text, IntWritable>
{
@Override
public void reduce(Text key, Iterable<IntWritable> values,Context context)
throws IOException, InterruptedException
{
int maxValue = Integer.MIN_VALUE;
for (IntWritable value : values) {
maxValue = Math.max(maxValue, value.get());
}
context.write(key, new IntWritable(maxValue));
}
}
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(Temp.class);
conf.setJobName("Temp");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
化妝jar文件,執行命令
hadoop jar Temp.jar Temp /hdfs_inputFile /hdfs_inputFile
相關問題
- 1. 鏈接Hadoop MapReduce 1.1.1示例
- 2. 的hadoop MaxTemperature例如不工作在VMware與Ubuntu 14.04
- 3. 錯誤運行的hadoop MapReduce的例子
- 4. hadoop的Dumbo mapreduce
- 5. Hadoop中的MapReduce
- 6. 在MapReduce中使用Hadoop的例外
- 7. hadoop mapreduce
- 8. 用於字符串轉換的Hadoop MapReduce示例
- 9. python mapreduce示例在hadoop中的最大/最小溫度
- 10. 無法執行基本的Hadoop Mapreduce Wordcount示例
- 11. 需要一些關於Hadoop Mapreduce的Kmean示例
- 12. 使用hadoop mapreduce與cassandra的示例代碼
- 13. mapreduce中的reducers hadoop
- 14. Hadoop MapReduce中的DataJoins
- 15. 拉上拉鍊的Hadoop MapReduce的
- 16. 大廈的Hadoop MapReduce的
- 17. 的Hadoop MapReduce的錯誤
- 18. 的Hadoop MapReduce的用java
- 19. 的Hadoop MapReduce的2.5.1凍結
- 20. Hadoop的 - 經典的MapReduce WORDCOUNT
- 21. 的Hadoop MapReduce的實踐
- 22. 的Hadoop MapReduce的錯誤:org.apache.hadoop.mapreduce.Counter
- 23. 的Hadoop MapReduce的鏈ArrayWritable
- 24. 的Hadoop MapReduce的getMapOutput失敗
- 25. Hadoop Mapreduce wordcount
- 26. Hadoop mapreduce編程
- 27. hadoop mapreduce model java
- 28. Hadoop和MapReduce
- 29. hadoop mapreduce teragen FAIL_CONTAINER_CLEANUP
- 30. hadoop mapreduce兩種
的Pssible重複http://stackoverflow.com/questions/19064300/mapreduce-java-program- to-calaculate-max-temperature-not-starting-to-run-it-is-r在這裏,您可以使用所有可以創建jar的代碼。你不會在hadoop安裝中獲得這個jar。 – SMA 2014-11-02 12:05:29