Configuration conf = new Configuration(); conf.set("fs.defaultFS", "hdfs://192.168.146.81:9000"); Job job = Job.getInstance(conf); job.setJarByClass(WeatherDriver.class); job.setMapperClass(WeatherMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(WeatherBean.class); job.setReducerClass(WeatherReducer.class); job.setOutputKeyClass(NullWritable.class); job.setOutputValueClass(WeatherBean.class); //job.setNumReduceTasks(0); FileInputFormat.setInputPaths(job, new Path("/weather/input/china_data.txt")); Path out = new Path("/weather/out"); FileSystem fs = FileSystem.get(new URI("hdfs://192.168.146.81:9000"), conf, "root"); if(fs.exists(out)) { fs.delete(out, true); } FileOutputFormat.setOutputPath(job, out); boolean flag = job.waitForCompletion(true); System.out.println(flag ? 0 : 1);是干啥的
时间: 2024-04-06 16:31:36 浏览: 21
这是一个使用Hadoop MapReduce框架实现的天气数据处理程序,主要功能是读取位于HDFS上的输入文件,对其中的数据进行处理,并将结果输出到HDFS上的指定目录。具体来说,该程序包括了一个Mapper类和一个Reducer类,Mapper类将输入数据进行拆分和转换,生成一系列键值对,Reducer类对这些键值对进行聚合和统计,最终输出结果。在代码中,还包括了一些与Hadoop相关的配置信息,以及一些文件读写和删除的操作。
相关问题
Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); 指定分布式系统
要在代码中指定使用分布式文件系统,需要使用`FileSystem.get()`方法的重载形式,并指定文件系统的URI和配置对象。例如:
```
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(new URI("hdfs://namenode1:8020"), conf);
```
这将返回一个指向分布式文件系统的文件系统对象,并使用指定的配置对象。在上面的例子中,文件系统的URI是`hdfs://namenode1:8020`,这意味着您的代码将连接到名为`namenode1`的NameNode节点,并使用默认的HDFS通信端口8020。
如果您的分布式文件系统启用了HA,您可以使用以下方式指定文件系统的URI:
```
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://mycluster");
conf.set("dfs.nameservices", "mycluster");
conf.set("dfs.client.failover.proxy.provider.mycluster",
"org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
FileSystem fs = FileSystem.get(new URI("hdfs://mycluster"), conf);
```
在上面的例子中,`fs.defaultFS`属性指定了文件系统的默认URI,`dfs.nameservices`属性指定了HA集群的名称,`dfs.client.failover.proxy.provider.mycluster`属性指定了故障转移代理提供程序的类名称,`FileSystem.get()`方法的参数为`hdfs://mycluster`,即HA集群的名称。
java.lang.IllegalArgumentException: Wrong FS: hdfs://node1/xiyou, expected: hdfs://hadoop01:8020
这个错误是因为你的代码中使用的文件系统不匹配。你的代码中使用了 `hdfs://node1/xiyou` 的文件系统,但是预期的文件系统应该是 `hdfs://hadoop01:8020`。这种情况通常是由于在代码中使用了错误的文件系统引起的。
要解决这个问题,你需要检查你的代码,确保你使用的文件系统与你期望的文件系统相匹配。你可以在代码中指定正确的文件系统,或者在运行代码之前设置环境变量来指定正确的文件系统。如果你使用的是 Hadoop,你可以通过设置 `HADOOP_CONF_DIR` 环境变量来指定 Hadoop 配置文件的位置,从而指定正确的文件系统。