public void readFile(String file) throws IOException {
Cofiguration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop-2.7.3/etc/hadoop/core-site.xml"))
conf.addResource(new Path("/usr/local/hadoop-2.7.3/etc/hadoop/hdfs-site.xml"))
conf.addResource(new Path("/usr/local/hadoop-2.7.3/etc/hadoop/mapred-site.xml"))
}
FileSystem fileSystem = FileSystem.get(conf);
System.out.println("DefaultFS: " + cong.get("fs.defaultFS"));
System.out.println("Home directory: " + fileSystem.getHomeDirectory());
Path path = new Path(file);
if(!fileSystem.exists(path)) {
System.out.println("File " + file + " does not exists");
return;
}
我是Hadoop的新手,我想知道是否可以使用" java -jar"来执行此Hadoop Java客户端代码。
我的代码使用" hadoop jar"命令。但是,当我尝试使用" java -jar"执行此代码时而不是" hadoop jar",它无法在HDFS中找到文件,方法getHomeDirectory()返回一个不存在的本地路径。
我的配置文件是否未正确添加?为什么代码仅在Hadoop命令下执行时才有效?
答案 0 :(得分:0)
SELECT department_number, count(*) FROM employee GROUP BY department_number