2011-02-13 49 views
2

我在Amazons EMR Hadoop实现之上运行python MapReduce脚本。由于主要脚本的结果,我获得了项目项目的相似性。在后续步骤中,我想将此输出分割为每个项目的单独S3存储区,因此每个项目存储区都包含与其类似的项目列表。为了达到这个目的,我想在后续步骤的reduce函数中使用Amazons boto python库。在Hadoop MapReduce脚本中导入外部库

  • 如何将外部(python)库导入到hadoop中,以便它们可以在使用python编写的reduce步骤中使用?
  • 是否可以在Hadoop环境中以这种方式访问​​S3?

由于提前, 托马斯

回答

4

当启动,您可以指定应提供外部文件Hadoop的过程。这是通过使用-files参数完成的。

$HADOOP_HOME/bin/hadoop jar /usr/lib/COMPANY/analytics/libjars/MyJar.jar -files hdfs://PDHadoop1.corp.COMPANY.com:54310/data/geoip/GeoIPCity.dat

我不知道,如果这些文件必须在HDFS,但如果它是要经常运行的工作,它不会是一个坏主意,把它们放在那里。
从你可以做一些类似的代码

if (DistributedCache.getLocalCacheFiles(context.getConfiguration()) != null) { 
    List<Path> localFiles = Utility.arrayToList(DistributedCache.getLocalCacheFiles(context.getConfiguration())); 
    for (Path localFile : localFiles) { 
     if ((localFile.getName() != null) && (localFile.getName().equalsIgnoreCase("GeoIPCity.dat"))) { 
      Path path = new File(localFile.toUri().getPath()); 
     } 
    } 
} 

这一切,但复制和直接从工作中我们映射器的多个代码粘贴。

我不知道你的问题的第二部分。希望第一部分的答案能让你开始。 :)

除了-files-libjars包括额外的罐子;我在这里有一些信息 - If I have a constructor that requires a path to a file, how can I "fake" that if it is packaged into a jar?