Hadoop天气系统

本文介绍了如何使用Hadoop MapReduce处理天气数据。首先,将计数程序打包成jar,然后将其上传到Hadoop集群节点。接着,通过hadoop jar命令运行该程序,并查看HDFS上的输出结果,包括使用ls命令列出输出文件及cat命令查看具体内容。
摘要由CSDN通过智能技术生成

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) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值