1.写完计数程序打包成jar
只要class文件即可
2.上传到node1上
3.hadoop jar weather.jar com.hadoop.mr.weather.WeatherSystem
hdfs dfs -ls /data/weather/output
hdfs dfs -cat /data/weather/output/part-r-00000
也可以把内容copy到当前的目录
hdfs dfs -get /data/weather/output/* ./
public class WeatherSystem {
public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration(true);
Job job = Job.getInstance(configuration);
job.setJarByClass(WeatherSystem.class);
job.setJobName("weather");
//map start
job.setMapperClass(WeatherMapper.class);
job.setMapOutputKeyClass(WeatherData.class);
job.setOutputValueClass(IntWritable.class);
job.setPartitionerClass(WeatherPartition.class);
job.setSortComparatorClass(WeatherComparator.class);
// job.setCombinerClass(cls);
//map end
//reduce start
job.setGroupingComparatorClass(WeatherGroupComparator.class);
job.setReducerClass(WeatherReducer.class);
job.setNumReduceTasks(2);
//reduce end
Path input = new Path("/data/weather/input/weather.txt");
FileInputFormat.addInputPath(job, input );
Path output = new Path("/data/weather/output");
//测试专用为防止出问题
if(output.getFileSystem(configuration).exists(output)){
output.getFileSystem(configuration).delete(output, true);
}
FileOutputFormat.setOutputPath(job, output);
// Submit the job, then poll for progress until the job is complete
job.waitForCompletion(true);
}
}
public class WeatherMapper extends Mapper<LongWritable, Text, WeatherData, IntWritable>{
private WeatherData wdkey = new WeatherData();
private final static IntWritable ivalue = new IntWritable(1);
public void map(LongWritable key, Text value, Context context)