Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement MapReduce engine

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to achieve the MapReduce engine, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

How to implement MapReduce engine

See below for the use example, only one name import is required.

#! / 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):

How to implement MapReduce engine

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

Then put mincemeat.py and example.py in the same directory and execute example.py

Python example.py

At this point the program will suspend a daemon

Then open another terminal to run:

Python mincemeat.py-p changeme localhost

You will see that the daemon just printed out the MapReduce result and exited.

{'averse: 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}

After reading the above, do you have any further understanding of how to implement the MapReduce engine? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report