java - 在hadoop中,如何通过initialize方法初始化DistributedFileSystem对象?

标签 java hadoop

有两个参数,一个 URI 和一个配置。我假设客户端设置的 JobConf 对象应该适用于配置,但是 URI 又如何呢?

这是我的驱动程序代码:

JobClient client = new JobClient();
JobConf conf = new JobConf(ClickViewSessions.class);

conf.setJobName("ClickViewSessions");

conf.setOutputKeyClass(LongWritable.class);
conf.setOutputValueClass(MinMaxWritable.class);

FileInputFormat.addInputPath(conf, new Path("input"));
FileOutputFormat.setOutputPath(conf, new Path("output"));

conf.setMapperClass(ClickViewSessionsMapper.class);
conf.setReducerClass(ClickViewSessionsReducer.class);

client.setConf(conf);

DistributedFileSystem dfs = new DistributedFileSystem();
try {
    dfs.initialize(new URI("blah") /* what goes here??? */, conf);
} catch (Exception e) {
    throw new RuntimeException(e.toString());
}

如何获取 URI 以提供给上面的 initialize 调用?

最佳答案

You could also use as shown below to intialize a file system

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

    public static void main(String args[]){
        try {
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", "hdfs://localhost:54310/user/hadoop/");
            FileSystem fs = FileSystem.get(conf);
            FileStatus[] status = fs.listStatus(new Path("."));
            for(int i=0;i<status.length;i++){
                System.out.println(status[i].getPath());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

关于java - 在hadoop中,如何通过initialize方法初始化DistributedFileSystem对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4728780/

相关文章:

java - 排序箭头 jtable 列标题

java - 如果Spring Batch满载,在哪里删除表?

hadoop - HBase 与 Java 8 和 zookeeper 有问题

hadoop - 使用hadoop hdfs将文件从我的虚拟机上传到另一个虚拟机

hadoop - HBase shell - 为历史数据和审计信息建模和检索数据

hadoop - 为 HCatalog 配置 HP Vertica 时找不到 hcatUtil

json - AWS Data Pipeline - 在创建 EMR 期间设置 Hive 站点值

java - 光规划器 :Error when displaying constraints scores

java - JPA 嵌套选择左外连接

java - 谁能帮我更正这段代码?