【问题标题】:java.lang.UnsupportedOperationException: Not implemented by the DistributedFileSystem FileSystem implementation during FileSystem.get()java.lang.UnsupportedOperationException:在 FileSystem.get() 期间未由 DistributedFileSystem FileSystem 实现实现
【发布时间】:2016-01-06 01:45:48
【问题描述】:

请在附件中找到一个代码 sn-p。我正在使用此代码将文件从 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

我错过了什么?

【问题讨论】:

    标签: java hadoop configuration hdfs


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      已解决

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

      【讨论】:

        【解决方案3】:

        您只需将您的配置对象指向您的 hdfs 服务器。采用 conf.set("fs.defaultFS", "hdfs://urlhere:8020");

        【讨论】:

        • 试过conf.set("fs.defaultFS", "hdfs://localhost:8020");。不工作。同样的错误。
        【解决方案4】:

        您缺少conf.addResources。您初始化了 Configuration 对象,但它仍然是空的。

        查看here 获取文档

        编辑: 试试这个:

        conf.addResource(new Path("<absolute file path>"))

        【讨论】:

        • 我需要添加哪些资源?我做了这样的事情conf.addResource("/usr/local/Cellar/hadoop/2.7.1/libexec/etc/hadoop/core-default.xml"); core-site, hdfs-site??
        • @frugalcoder 自从我使用 hdfs 以来已经有一段时间了,但我想这很可能是配置 xml 文件
        • @frugalcoder 也许是这样的:conf.addResource(new File("../resource.xml").toURI().toURL());
        • 我得到文件未找到异常。即使文件在那里。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多