繁体   English   中英

使用 HadoopInputFile 从 S3 读取文件会产生 FileNotFoundException

[英]Reading files from S3 using HadoopInputFile yields FileNotFoundException

我正在尝试从 S3 的目录中读取镶木地板文件

val bucketKey = "s3a://foo/direcoty_to_retrieve/"
val conf: Configuration = new Configuration()
conf.setBoolean(AvroReadSupport.AVRO_COMPATIBILITY, true)
val inputFile = HadoopInputFile.fromPath(new Path(bucketKey), conf)
val reader: ParquetReader[GenericRecord] =  AvroParquetReader.builder[GenericRecord](inputFile).withConf(conf).build()

但是我越来越

Exception in thread "main" java.io.FileNotFoundException: No such file or directory: s3a://foo/direcoty_to_retrieve
    at org.apache.hadoop.fs.s3a.S3AFileSystem.s3GetFileStatus(S3AFileSystem.java:3356)
    at org.apache.hadoop.fs.s3a.S3AFileSystem.innerGetFileStatus(S3AFileSystem.java:3185)
    at org.apache.hadoop.fs.s3a.S3AFileSystem.getFileStatus(S3AFileSystem.java:3053)
    at org.apache.parquet.hadoop.util.HadoopInputFile.fromPath(HadoopInputFile.java:39)

编辑:当我将AvroParquetReader.builderfilePath一起使用时,例如:

val reader: ParquetReader[GenericRecord] =  AvroParquetReader.builder[GenericRecord](new Path(bucketKey)).withConf(conf).build()

它可以工作,但是这个选项已被弃用,我宁愿不使用它。 在本地目录上它可以工作。 我的AWS_ACCESS_KEYAWS_SECRET_ACCESS_KEY变量设置正确。 可能是什么问题?

我在通过Alpakka Avro 镶木地板库(取决于parquet-hadoop-1.10.1.jar )从 Amazon S3 存储读取镶木地板文件时遇到了同样的问题。 经过一些调试后,我在ParquetReader.build方法中发现了问题。

public ParquetReader<T> build() throws IOException {
  ParquetReadOptions options = optionsBuilder.build();

  if (path != null) {
    FileSystem fs = path.getFileSystem(conf);
    FileStatus stat = fs.getFileStatus(path);

    if (stat.isFile()) {
      return new ParquetReader<>(
          Collections.singletonList((InputFile) HadoopInputFile.fromStatus(stat, conf)),
          options,
          getReadSupport());

    } else {
      List<InputFile> files = new ArrayList<>();
      for (FileStatus fileStatus : fs.listStatus(path, HiddenFileFilter.INSTANCE)) {
        files.add(HadoopInputFile.fromStatus(fileStatus, conf));
      }
      return new ParquetReader<T>(files, options, getReadSupport());
    }

  } else {
    return new ParquetReader<>(Collections.singletonList(file), options, getReadSupport());
  }
}

HadoopInputFile用作输入时,构建器path属性设置为null并且读取器在 else 块中启动。 由于镶木地板文件表示为文件系统中的目录,这导致java.io.FileNotFoundException

现在的解决方案是使用已弃用的方法:

AvroParquetReader.builder[GenericRecord](new Path(bucketKey)).withConf(conf).build()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM