溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

MapReduce引擎如何實現(xiàn)

發(fā)布時間:2021-06-26 14:09:23 來源:億速云 閱讀:167 作者:Leah 欄目:數(shù)據(jù)庫

今天就跟大家聊聊有關(guān)MapReduce引擎如何實現(xiàn),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

   MapReduce引擎怎么實現(xiàn)

  使用例子見下,只需要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引擎怎么實現(xiàn)

  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 放在同一個目錄下,執(zhí)行example.py

  python example.py

  這時程序會掛起一個daemon

  然后另開一終端運行:

  python mincemeat.py -p changeme localhost

  就會看到剛才的daemon打印出了MapReduce結(jié)果并退出了。

  {‘a(chǎn)’: 2, ‘on’: 1, ‘great’: 1, ‘Humpty’: 3, ‘a(chǎn)gain’: 1, ‘wall’: 1, ‘Dumpty’: 2, ‘men’: 1, ‘had’: 1, ‘a(chǎn)ll’: 1, ‘together’: 1, “King’s”: 2, ‘horses’: 1, ‘All’: 1, “Couldn’t”: 1, ‘fall’: 1, ‘a(chǎn)nd’: 1, ‘the’: 2, ‘put’: 1, ’sat’: 1}

看完上述內(nèi)容,你們對MapReduce引擎如何實現(xiàn)有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI