java.lang.UnsupportedOperationException:FileSystem.get()期间未由DistributedFileSystem FileSystem实现实现

时间:2015-10-08 12:25:44

标签: java hadoop configuration hdfs

请查找附件中的代码段。我正在使用此代码将文件从hdfs下载到我的本地文件系统 -

    Configuration conf = new Configuration();

    FileSystem hdfsFileSystem = FileSystem.get(conf);

    Path local = new Path(destinationPath);
    Path hdfs = new Path(sourcePath);

    String fileName = hdfs.getName();

    if (hdfsFileSystem.exists(hdfs))
    {
        hdfsFileSystem.copyToLocalFile(false, hdfs, local, true);
        logger.info("File " + fileName + " copied to local machine on location: " + destinationPath);
    }
    else
    {
        logger.error("File " + fileName + " does not exist on HDFS on location: " + sourcePath);
    }

运行此命令会提供以下输出 -

Exception in thread "main" java.lang.UnsupportedOperationException: Not implemented by the DistributedFileSystem FileSystem implementation
at org.apache.hadoop.fs.FileSystem.getScheme(FileSystem.java:217)
at org.apache.hadoop.fs.FileSystem.loadFileSystems(FileSystem.java:2624)
at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2634)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2651)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:92)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2687)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2669)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:371)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:170)
at com.flipkart.ads.importer.HdfsToLocalImporter.importFile(HdfsToLocalImporter.java:35)
at com.flipkart.ads.importer.HdfsToLocalImporter.main(HdfsToLocalImporter.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Process finished with exit code 1

我错过了什么?

4 个答案:

答案 0 :(得分:16)

<强>解决

没有想到我的想法。这是一个罐子不匹配的问题。 Hadoop-code和Hadoop-commons提供相同的jar,我已经包含了两个依赖项。

答案 1 :(得分:3)

检查您的构建路径。如果您在那里看到hadoop-core *****。jar,请删除它。这不是必需的。这将解决问题

答案 2 :(得分:2)

您只需将Configuration对象指向hdfs服务器即可。使用  conf.set("fs.defaultFS", "hdfs://urlhere:8020");

答案 3 :(得分:1)

您缺少Configuration。您初始化了conf.addResource(new Path("<absolute file path>"))对象,但它仍然是空的。

检查here以获取文档

修改 试试这个:

{{1}}