绝对:)您可以像这样使用Hadoop流:
在从stdin读取的lua中创建映射器和/或reducer脚本:
#!/usr/bin/env lua
while true do
local line = io.read()
if line == nil then break end
# Do something with the incoming row
end
Run Code Online (Sandbox Code Playgroud)
然后运行你的工作:
$HADOOP_HOME/bin/hadoop jar $HADOOP_HOME/hadoop-streaming.jar \
-input myInputDirs \
-output myOutputDir \
-mapper myMapper.lua \
-reducer myReducer.lua \
-file /local/path/to/myMapper.lua
-file /local/path/to/myReducer.lua
Run Code Online (Sandbox Code Playgroud)
在这里,您使用-mapper和指定mapper和reducer脚本,-reducer并将这两个脚本一起-file发送到分布式缓存,以便所有任务跟踪器都可以访问它.
使用流式传输时,您需要确保lua在运行任务跟踪器的所有计算机上都可以使用.
前段时间,我们尝试使用luajitPig(速度非常快)来从Pig流式传输.如果您使用Pig,您可以执行以下操作:
OP = stream IP through `/local/path/to/script`;
Run Code Online (Sandbox Code Playgroud)
这与使用lua作为映射器或缩减器不同,但是根据操作发生的位置,mapper或reducer的输出将通过脚本进行流式处理.