将文件从s3 bucket导入hadoop程序(在java、eclipse中)

mw3dktmi  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(276)

我正在尝试将缓存文件添加到我的工作中。我在s3 bucket目录中拆分了文件。”s3n:pathsomthing“我想在mapper类的设置中导入它们。
我主要尝试了以下代码:

  1. job.addCacheFile(new URI(args[1])); //path of the s3 with the files

在Map器中,在我使用的设置中:

  1. protected void setup(Context context) throws IOException, InterruptedException {
  2. Configuration conf = context.getConfiguration();
  3. FileSystem fs = FileSystem.get(conf);
  4. System.out.println("entring setup");
  5. URI [] cacheFiles = context.getCacheFiles();
  6. if((cacheFiles != null) && (cacheFiles.length >0)) {
  7. for (URI cacheFile : cacheFiles) {
  8. Path path = new Path(cacheFile.getPath().toString());
  9. if (fs.exists(path)) {
  10. FSDataInputStream in = fs.open(path);
  11. readFile(in);
  12. in.close();
  13. }
  14. }
  15. }

打开和读取整个文件的正确方法是什么?
谢谢您!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题