擅长:python、mysql、java
<p>经过大量的google搜索(等等),我发现了如何包含可执行的二进制文件/脚本/模块,这些文件可以被映射器/还原器访问。诀窍是先将所有文件上传到hadoop。在</p>
<pre><code>$ bin/hadoop dfs -copyFromLocal /local/file/system/module.py module.py
</code></pre>
<p>然后,您需要将流式处理命令格式化为以下模板:</p>
^{pr2}$
<p>如果要链接python模块,则需要将以下代码添加到mapper/reducer脚本中:</p>
<pre><code>import sys
sys.path.append('.')
import module
</code></pre>
<p>如果通过子处理访问二进制文件,则命令应该如下所示:</p>
<pre><code>cli = "./binary %s" % (argument)
cli_parts = shlex.split(cli)
mp = Popen(cli_parts, stdin=PIPE, stderr=PIPE, stdout=PIPE)
mp.communicate()[0]
</code></pre>
<p>希望这有帮助。在</p>