在 Ubuntu 虚拟机上,我根据 Michael Noll 的 tutorial 设置了一个单节点集群这是我编写 Hadoop 程序的起点。
另外,作为引用,this .
我的程序使用 Python 并使用 Hadoop Streaming。
我写了一个简单的向量乘法程序,其中 mapper.py 接受输入文件 v1 和 v2,每个文件都包含一个向量12,33,10 并返回产品。然后 reducer.py 返回乘积之和,即:
映射器:map(mult,v1,v2)
reducer:sum(p1,p2,p3,...,pn)
映射器.py :
import sys
def mult(x,y):
return int(x)*int(y)
# Input comes from STDIN (standard input).
inputvec = tuple()
for i in sys.stdin:
i = i.strip()
inputvec += (tuple(i.split(",")),)
v1 = inputvec[0]
v2 = inputvec[1]
results = map(mult, v1, v2)
# Simply printing the results variable would print the tuple. This
# would be fine except that the STDIN of reduce.py takes all the
# output as input, including brackets, which can be problematic
# Cleaning the output ready to be input for the Reduce step:
for o in results:
print ' %s' % o,
reducer.py:
import sys
result = int()
for a in sys.stdin:
a = a.strip()
a = a.split()
for r in range(len(a)):
result += int(a[r])
print result
在 in 子目录中,我有 v1 包含 5,12,20 和 v2 包含 14,11,3。
在本地测试,一切按预期工作:
hduser@ubuntu:~/VectMult$ cat in/* | python ./mapper.py
70 132 60
hduser@ubuntu:~/VectMult$ cat in/* | python ./mapper.py | sort
70 132 60
hduser@ubuntu:~/VectMult$ cat in/* | python ./mapper.py | sort | python ./reducer.py
262
当我在 Hadoop 中运行它时,它似乎成功运行并且没有抛出任何异常:
hduser@ubuntu:/usr/local/hadoop$ bin/hadoop jar contrib/streaming/hadoop-*streaming*.jar -mapper python /home/hduser/VectMult3/mapper.py -reducer python /home/hduser/VectMult3/reducer.py -input /home/hduser/VectMult3/in -output /home/hduser/VectMult3/out4
Warning: $HADOOP_HOME is deprecated.
packageJobJar: [/app/hadoop/tmp/hadoop-unjar2168776605822419867/] [] /tmp/streamjob6920304075078514767.jar tmpDir=null
12/11/18 21:20:09 INFO util.NativeCodeLoader: Loaded the native-hadoop library
12/11/18 21:20:09 WARN snappy.LoadSnappy: Snappy native library not loaded
12/11/18 21:20:09 INFO mapred.FileInputFormat: Total input paths to process : 2
12/11/18 21:20:09 INFO streaming.StreamJob: getLocalDirs(): [/app/hadoop/tmp/mapred/local]
12/11/18 21:20:09 INFO streaming.StreamJob: Running job: job_201211181903_0009
12/11/18 21:20:09 INFO streaming.StreamJob: To kill this job, run:
12/11/18 21:20:09 INFO streaming.StreamJob: /usr/local/hadoop/libexec/../bin/hadoop job -Dmapred.job.tracker=localhost:54311 -kill job_201211181903_0009
12/11/18 21:20:09 INFO streaming.StreamJob: Tracking URL: http://localhost:50030/jobdetails.jsp?jobid=job_201211181903_0009
12/11/18 21:20:10 INFO streaming.StreamJob: map 0% reduce 0%
12/11/18 21:20:24 INFO streaming.StreamJob: map 67% reduce 0%
12/11/18 21:20:33 INFO streaming.StreamJob: map 100% reduce 0%
12/11/18 21:20:36 INFO streaming.StreamJob: map 100% reduce 22%
12/11/18 21:20:45 INFO streaming.StreamJob: map 100% reduce 100%
12/11/18 21:20:51 INFO streaming.StreamJob: Job complete: job_201211181903_0009
12/11/18 21:20:51 INFO streaming.StreamJob: Output: /home/hduser/VectMult3/out4
hduser@ubuntu:/usr/local/hadoop$ bin/hadoop dfs -cat /home/hduser/VectMult3/out4/part-00000
Warning: $HADOOP_HOME is deprecated.
hduser@ubuntu:/usr/local/hadoop$ bin/hadoop dfs -ls /home/hduser/VectMult3/out4/
Warning: $HADOOP_HOME is deprecated.
Found 3 items
-rw-r--r-- 1 hduser supergroup 0 2012-11-18 22:05 /home/hduser/VectMult3/out4/_SUCCESS
drwxr-xr-x - hduser supergroup 0 2012-11-18 22:05 /home/hduser/VectMult3/out4/_logs
-rw-r--r-- 1 hduser supergroup 0 2012-11-18 22:05 /home/hduser/VectMult3/out4/part-00000
但是当我检查输出时,我发现的只是一个 0 字节的空文件。
我不知道哪里出了问题。谁能帮忙?
编辑:对@DiJuMx 的回应
解决此问题的一种方法是从 map 输出到一个临时文件,然后在 reduce 中使用该临时文件。
不确定 Hadoop 是否允许这样做?希望有更了解的人可以纠正我这一点。
在尝试此操作之前,请尝试编写一个更简单的版本,它只直接传递数据而不进行任何处理。
我认为这是个好主意,只是为了检查数据是否正确流过。我为此使用了以下内容:
mapper.py 和 reducer.py
导入系统
for i in sys.stdin:
print i,
出来的应该和进去的一样。仍然输出一个空文件。
或者,如果输入为空,则在 reduce 中编辑现有代码以向输出文件输出一条(错误)消息
映射器.py
import sys
for i in sys.stdin:
print "mapped",
print "mapper",
reducer.py
import sys
for i in sys.stdin:
print "reduced",
print "reducer",
如果收到输入,它最终应该输出reduced。无论哪种方式,它至少应该输出 reducer。实际输出仍然是一个空文件。
最佳答案
我没有任何使用 hadoop(或 python 的经验),但是,我确实注意到您正在指定要转到 /home/hduser/VectMult3/out4 的输出但希望它位于 /home/hduser/VectMult3/out/part-00000 中。
您是否检查过 out4 文件是否存在及其内容?
关于Python 代码有效,但 Hadoop Streaming 生成 part-00000 "Empty file",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13445126/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A
这是一道面试题,我没有答对,但还是很好奇怎么解。你有N个人的大家庭,分别是1,2,3,...,N岁。你想给你的大家庭拍张照片。所有的家庭成员都排成一排。“我是家里的friend,建议家庭成员安排如下:”1岁的家庭成员坐在这一排的最左边。每两个坐在一起的家庭成员的年龄相差不得超过2岁。输入:整数N,1≤N≤55。输出:摄影师可以拍摄的照片数量。示例->输入:4,输出:4符合条件的数组:[1,2,3,4][1,2,4,3][1,3,2,4][1,3,4,2]另一个例子:输入:5输出:6符合条件的数组:[1,2,3,4,5][1,2,3,5,4][1,2,4,3,5][1,2,4,5,3][