首頁  >  文章  >  後端開發  >  使用Python編寫MapReduce作業

使用Python編寫MapReduce作業

高洛峰
高洛峰原創
2016-10-18 10:28:521335瀏覽

mrjob 可以讓用Python 2.5+ 來編寫MapReduce 作業,並在多個不同平台上運行,你可以:

使用純Python 編寫多步驟的MapReduce 作業

在本機上進行測試

在Hadoop 叢集上運行

使用Amazon Elastic MapReduce (EMR) 在雲端上運行

pip 的安裝方法非常簡單,無需配置,直接運行:pip install mrjob

程式碼實例:

from mrjob.job import MRJob
class MRWordCounter(MRJob):
    def mapper(self, key, line):
        for word in line.split():
            yield word, 1
    def reducer(self, word, occurrences):
        yield word, sum(occurrences)
if __name__ == '__main__':
    MRWordCounter.run()


🎜
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn