共計 1001 個字符,預計需要花費 3 分鐘才能閱讀完成。
自動寫代碼機器人,免費開通
今天就跟大家聊聊有關 MapReduce 引擎如何實現,可能很多人都不太了解,為了讓大家更加了解,丸趣 TV 小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
MapReduce 引擎怎么實現
使用例子見下,只需要 import 一個名即可。
#!/usr/bin/env python
import mincemeat
data = [Humpty Dumpty sat on a wall ,
Humpty Dumpty had a great fall ,
All the King s horses and all the King s men ,
Couldn t put Humpty together again ,
]
def mapfn(k, v):
for w in v.split():
yield w, 1
def reducefn(k, vs):
MapReduce 引擎怎么實現
result = 0
for v in vs:
result += v
return result
s = mincemeat.Server()
# The data source can be any dictionary-like object
s.datasource = dict(enumerate(data))
s.mapfn = mapfn
s.reducefn = reducefn
results = s.run_server(password= changeme)
print results
然后將 mincemeat.py 和 example.py 放在同一個目錄下,執行 example.py
python example.py
這時程序會掛起一個 daemon
然后另開一終端運行:
python mincemeat.py -p changeme localhost
就會看到剛才的 daemon 打印出了 MapReduce 結果并退出了。
{‘a’: 2,‘on’: 1,‘great’: 1,‘Humpty’: 3,‘again’: 1,‘wall’: 1,‘Dumpty’: 2,‘men’: 1,‘had’: 1,‘all’: 1,‘together’: 1,“King’s”: 2,‘horses’: 1,‘All’: 1,“Couldn’t”: 1,‘fall’: 1,‘and’: 1,‘the’: 2,‘put’: 1,’sat’: 1}
看完上述內容,你們對 MapReduce 引擎如何實現有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注丸趣 TV 行業資訊頻道,感謝大家的支持。
向 AI 問一下細節