SlideShare une entreprise Scribd logo
1  sur  9
Map Reduce
LA PRATIQUE
TP1 : Map reduce en python
 Le Hello World du Map Reduce : compter les mots
 Vous avez à coder plusieurs modules :
 Mapper.py
 Qui lit un texte sur l’entrée standard
 Et qui renvoie un doublet : mot tabulation (t) 1 retour à la ligne (n)
sur la sortie standard
 Reducer.py
 Qui lit les doublets depuis l’entrée standard
 Qui calcule le nombre d’occurrence d’un mot
2
Résultats attendus 3
echo "foo foo quux labs foo bar quux" | /home/hduser/mapper.py
foo 1
foo 1
quux 1
labs 1
foo 1
bar 1
quux 1
echo "foo foo quux labs foo bar quux" | /home/hduser/mapper.py | sort -k1,1 | /home/hduser/reducer.py
bar 1
foo 3
labs 1
quux 2
Pure Python fonction map 4
map(function_to_apply, list_of_inputs)
Cela permet de remplacer un code comme celui-ci
item = [1,2,3,4,5]
carres = []
for i in items:
carres.append(i**2)
item = [1,2,3,4,5]
Carres = list(map(lambda x: x**2, items))
par
Pure Python fonction filter 5
filter(function_to_apply, list_of_inputs)
Agit comme une boucle mais c’est une fonction interne, plus rapide
liste = range(-5, 5)
negatifs = list(filter(lambda x: x<0, liste))
[-5, -4, -3, -2, -1]
renvoie
Pure Python fonction reduce 6
reduce(function_to_apply, list_of_inputs)
Cela permet de remplacer un code comme celui-ci
produit = 1
list = [1, 2, 3, 4]
for num in list:
produit = produit * num
from functools import reduce
list = [1, 2, 3, 4]
produit = reduce((lambda x,y: x*y), list)
par
Map 7
#!/usr/bin/env python
"""mapper.py"""
import sys
# input comes from STDIN (standard input)
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()
# split the line into words
words = line.split()
# increase counters
for word in words:
# write the results to STDOUT (standard output);
# what we output here will be the input for the
# Reduce step, i.e. the input for reducer.py
#
# tab-delimited; the trivial word count is 1
print('%st%s' % (word, 1) )
Reduce 8
#!/usr/bin/env python
from operator import itemgetter
import sys
current_word = None
current_count = 0
word = None
for line in sys.stdin:
line = line.strip()
word, count = line.split('t', 1)
try:
count = int(count)
except ValueError:
# count was not a number, so silently
# ignore/discard this line
continue
if current_word == word:
current_count += count
else:
if current_word:
print('%st%s' % (current_word, current_count))
current_count = count
current_word = word
if current_word == word:
print('%st%s' % (current_word, current_count))
Pipe (/Paipe/)
 Toutes les commandes un*x ont trois moyens de communiquer avec
l’utilisateur
 Un moyen de lire ce qu’il demande (par défaut par le clavier) : stdin
 Un moyen de transmettre des informations (par défaut à l’écran) : stdout
 Un moyen de signaler les erreurs (par défaut à l’écran) : stderr
 Un*x permet de chainer les commandes
 On relie le stdout d’un programme au stdin du suivant
 C’est la commande pipe, notée |
9

Contenu connexe

Tendances

Fiche3 ex-sous-programme
Fiche3 ex-sous-programmeFiche3 ex-sous-programme
Fiche3 ex-sous-programmeBaghdadi Wajih
 
Corrigé iscae informatique 2014
Corrigé iscae informatique 2014Corrigé iscae informatique 2014
Corrigé iscae informatique 2014Yassine Anddam
 
Lect14 dev2
Lect14 dev2Lect14 dev2
Lect14 dev2moisko
 
Return Type Declaration
Return Type DeclarationReturn Type Declaration
Return Type DeclarationDarkmira
 
La programmation fonctionnelle avec le langage OCaml
La programmation fonctionnelle avec le langage OCamlLa programmation fonctionnelle avec le langage OCaml
La programmation fonctionnelle avec le langage OCamlStéphane Legrand
 
Good or Evil: les fonctions anonymes en Javascript
Good or Evil: les fonctions anonymes en JavascriptGood or Evil: les fonctions anonymes en Javascript
Good or Evil: les fonctions anonymes en JavascriptNoirdes
 
The iTronics Internet of things Workshop 27-05-2017 - get started
The iTronics Internet of things Workshop 27-05-2017 - get startedThe iTronics Internet of things Workshop 27-05-2017 - get started
The iTronics Internet of things Workshop 27-05-2017 - get startedRomaric Saounde Tsopnang
 
ALF 10 - Convention d'appel de fonction
ALF 10 - Convention d'appel de fonctionALF 10 - Convention d'appel de fonction
ALF 10 - Convention d'appel de fonctionAlexandru Radovici
 
2- The iTronics Internet of things Workshop 27-05-2017 - GPIO
2- The iTronics Internet of things Workshop 27-05-2017 - GPIO2- The iTronics Internet of things Workshop 27-05-2017 - GPIO
2- The iTronics Internet of things Workshop 27-05-2017 - GPIORomaric Saounde Tsopnang
 
The iTronics - Arduino + Raspberry Pi Workshop 20-04-2017
The iTronics - Arduino + Raspberry Pi Workshop 20-04-2017The iTronics - Arduino + Raspberry Pi Workshop 20-04-2017
The iTronics - Arduino + Raspberry Pi Workshop 20-04-2017Romaric Saounde Tsopnang
 
ALF 3 - Expressions régulières et Lexer
ALF 3 - Expressions régulières et Lexer ALF 3 - Expressions régulières et Lexer
ALF 3 - Expressions régulières et Lexer Alexandru Radovici
 
Correction dc3 3sc2
Correction dc3 3sc2Correction dc3 3sc2
Correction dc3 3sc2Hela Ch
 
Monitoring d'applications/environnements PHP: APM et Pinba
Monitoring d'applications/environnements PHP: APM et PinbaMonitoring d'applications/environnements PHP: APM et Pinba
Monitoring d'applications/environnements PHP: APM et PinbaPatrick Allaert
 
Programming language python 2021
Programming language python 2021Programming language python 2021
Programming language python 2021Dalila Chouaya
 
Null Coalescing Operator
Null Coalescing OperatorNull Coalescing Operator
Null Coalescing OperatorDarkmira
 
Présentation Scala
Présentation ScalaPrésentation Scala
Présentation Scalajeremy guido
 

Tendances (20)

Fiche3 ex-sous-programme
Fiche3 ex-sous-programmeFiche3 ex-sous-programme
Fiche3 ex-sous-programme
 
Google Developer Group (GDG) Aix-Marseille #1 (27/08/2018)
Google Developer Group (GDG) Aix-Marseille #1 (27/08/2018)Google Developer Group (GDG) Aix-Marseille #1 (27/08/2018)
Google Developer Group (GDG) Aix-Marseille #1 (27/08/2018)
 
Corrigé iscae informatique 2014
Corrigé iscae informatique 2014Corrigé iscae informatique 2014
Corrigé iscae informatique 2014
 
ALF 8 - Generation de code
ALF 8 - Generation de codeALF 8 - Generation de code
ALF 8 - Generation de code
 
Lect14 dev2
Lect14 dev2Lect14 dev2
Lect14 dev2
 
Return Type Declaration
Return Type DeclarationReturn Type Declaration
Return Type Declaration
 
La programmation fonctionnelle avec le langage OCaml
La programmation fonctionnelle avec le langage OCamlLa programmation fonctionnelle avec le langage OCaml
La programmation fonctionnelle avec le langage OCaml
 
Good or Evil: les fonctions anonymes en Javascript
Good or Evil: les fonctions anonymes en JavascriptGood or Evil: les fonctions anonymes en Javascript
Good or Evil: les fonctions anonymes en Javascript
 
The iTronics Internet of things Workshop 27-05-2017 - get started
The iTronics Internet of things Workshop 27-05-2017 - get startedThe iTronics Internet of things Workshop 27-05-2017 - get started
The iTronics Internet of things Workshop 27-05-2017 - get started
 
ALF 10 - Convention d'appel de fonction
ALF 10 - Convention d'appel de fonctionALF 10 - Convention d'appel de fonction
ALF 10 - Convention d'appel de fonction
 
2- The iTronics Internet of things Workshop 27-05-2017 - GPIO
2- The iTronics Internet of things Workshop 27-05-2017 - GPIO2- The iTronics Internet of things Workshop 27-05-2017 - GPIO
2- The iTronics Internet of things Workshop 27-05-2017 - GPIO
 
ALF 11 - WebAssembly
ALF 11 - WebAssemblyALF 11 - WebAssembly
ALF 11 - WebAssembly
 
The iTronics - Arduino + Raspberry Pi Workshop 20-04-2017
The iTronics - Arduino + Raspberry Pi Workshop 20-04-2017The iTronics - Arduino + Raspberry Pi Workshop 20-04-2017
The iTronics - Arduino + Raspberry Pi Workshop 20-04-2017
 
Go
GoGo
Go
 
ALF 3 - Expressions régulières et Lexer
ALF 3 - Expressions régulières et Lexer ALF 3 - Expressions régulières et Lexer
ALF 3 - Expressions régulières et Lexer
 
Correction dc3 3sc2
Correction dc3 3sc2Correction dc3 3sc2
Correction dc3 3sc2
 
Monitoring d'applications/environnements PHP: APM et Pinba
Monitoring d'applications/environnements PHP: APM et PinbaMonitoring d'applications/environnements PHP: APM et Pinba
Monitoring d'applications/environnements PHP: APM et Pinba
 
Programming language python 2021
Programming language python 2021Programming language python 2021
Programming language python 2021
 
Null Coalescing Operator
Null Coalescing OperatorNull Coalescing Operator
Null Coalescing Operator
 
Présentation Scala
Présentation ScalaPrésentation Scala
Présentation Scala
 

Similaire à 09 big data mapreduce

09 big data mapreduce
09 big data mapreduce09 big data mapreduce
09 big data mapreducePatrick Bury
 
C1 - Langage C - ISIMA - Première partie
C1 - Langage C - ISIMA - Première partieC1 - Langage C - ISIMA - Première partie
C1 - Langage C - ISIMA - Première partieLoic Yon
 
Formation python
Formation pythonFormation python
Formation pythonj_lipaz
 
Cours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMACours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMALoic Yon
 
Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Fahad Golra
 
Tp1 compte rendu en langage c
Tp1 compte rendu en langage cTp1 compte rendu en langage c
Tp1 compte rendu en langage cEbrima NJIE
 
Introduction à Python - Achraf Kacimi El Hassani
Introduction à Python - Achraf Kacimi El HassaniIntroduction à Python - Achraf Kacimi El Hassani
Introduction à Python - Achraf Kacimi El HassaniShellmates
 
Interception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appelInterception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appelThierry Gayet
 
01 - Introduction à Python chaines de caractères.pdf
01 - Introduction à Python chaines de caractères.pdf01 - Introduction à Python chaines de caractères.pdf
01 - Introduction à Python chaines de caractères.pdfMARYAM510573
 
02 Spécificité du C++ COURS SYS SYSSSSSS
02 Spécificité du C++  COURS SYS SYSSSSSS02 Spécificité du C++  COURS SYS SYSSSSSS
02 Spécificité du C++ COURS SYS SYSSSSSSAyoubElmrabet6
 
Python avancé : Ensemble, dictionnaire et base de données
Python avancé : Ensemble, dictionnaire et base de donnéesPython avancé : Ensemble, dictionnaire et base de données
Python avancé : Ensemble, dictionnaire et base de donnéesECAM Brussels Engineering School
 
Seance 4- Programmation en langage C
Seance 4- Programmation en langage CSeance 4- Programmation en langage C
Seance 4- Programmation en langage CFahad Golra
 
Chap 1 Initiation.pptx
Chap 1 Initiation.pptxChap 1 Initiation.pptx
Chap 1 Initiation.pptxolfaharrabi2
 
R fait du la tex
R fait du la texR fait du la tex
R fait du la texCdiscount
 

Similaire à 09 big data mapreduce (20)

09 big data mapreduce
09 big data mapreduce09 big data mapreduce
09 big data mapreduce
 
C++ 11/14
C++ 11/14C++ 11/14
C++ 11/14
 
C1 - Langage C - ISIMA - Première partie
C1 - Langage C - ISIMA - Première partieC1 - Langage C - ISIMA - Première partie
C1 - Langage C - ISIMA - Première partie
 
Formation python
Formation pythonFormation python
Formation python
 
Cours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMACours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMA
 
COURS_PYTHON_22.ppt
COURS_PYTHON_22.pptCOURS_PYTHON_22.ppt
COURS_PYTHON_22.ppt
 
Formation python
Formation pythonFormation python
Formation python
 
Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Seance 3- Programmation en langage C
Seance 3- Programmation en langage C
 
Theme 6
Theme 6Theme 6
Theme 6
 
Tp1 compte rendu en langage c
Tp1 compte rendu en langage cTp1 compte rendu en langage c
Tp1 compte rendu en langage c
 
Introduction à Python - Achraf Kacimi El Hassani
Introduction à Python - Achraf Kacimi El HassaniIntroduction à Python - Achraf Kacimi El Hassani
Introduction à Python - Achraf Kacimi El Hassani
 
Interception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appelInterception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appel
 
01 - Introduction à Python chaines de caractères.pdf
01 - Introduction à Python chaines de caractères.pdf01 - Introduction à Python chaines de caractères.pdf
01 - Introduction à Python chaines de caractères.pdf
 
Chap1_Entrees_Sorties.pptx
Chap1_Entrees_Sorties.pptxChap1_Entrees_Sorties.pptx
Chap1_Entrees_Sorties.pptx
 
02 Spécificité du C++ COURS SYS SYSSSSSS
02 Spécificité du C++  COURS SYS SYSSSSSS02 Spécificité du C++  COURS SYS SYSSSSSS
02 Spécificité du C++ COURS SYS SYSSSSSS
 
Python avancé : Ensemble, dictionnaire et base de données
Python avancé : Ensemble, dictionnaire et base de donnéesPython avancé : Ensemble, dictionnaire et base de données
Python avancé : Ensemble, dictionnaire et base de données
 
Seance 4- Programmation en langage C
Seance 4- Programmation en langage CSeance 4- Programmation en langage C
Seance 4- Programmation en langage C
 
POO-chapitre2.pptx
POO-chapitre2.pptxPOO-chapitre2.pptx
POO-chapitre2.pptx
 
Chap 1 Initiation.pptx
Chap 1 Initiation.pptxChap 1 Initiation.pptx
Chap 1 Initiation.pptx
 
R fait du la tex
R fait du la texR fait du la tex
R fait du la tex
 

Plus de Patrick Bury

16 graph databases
16 graph databases16 graph databases
16 graph databasesPatrick Bury
 
15 map reduce on azure
15 map reduce on azure15 map reduce on azure
15 map reduce on azurePatrick Bury
 
14 big data gitlab
14 big data gitlab14 big data gitlab
14 big data gitlabPatrick Bury
 
13 big data docker
13 big data docker13 big data docker
13 big data dockerPatrick Bury
 
10 big data hadoop
10 big data hadoop10 big data hadoop
10 big data hadoopPatrick Bury
 
08 big data dataviz
08 big data dataviz08 big data dataviz
08 big data datavizPatrick Bury
 
06 cloud souverain
06 cloud souverain06 cloud souverain
06 cloud souverainPatrick Bury
 
05 creation instance ovh
05 creation instance ovh05 creation instance ovh
05 creation instance ovhPatrick Bury
 
04 big data fournisseurs
04 big data fournisseurs04 big data fournisseurs
04 big data fournisseursPatrick Bury
 
03 big data stockage
03 big data stockage03 big data stockage
03 big data stockagePatrick Bury
 
03 big data échelle
03 big data échelle03 big data échelle
03 big data échellePatrick Bury
 
02 big data definition
02 big data definition02 big data definition
02 big data definitionPatrick Bury
 
01 big data introduction
01 big data introduction01 big data introduction
01 big data introductionPatrick Bury
 
16 graph databases
16 graph databases16 graph databases
16 graph databasesPatrick Bury
 
15 map reduce on azure
15 map reduce on azure15 map reduce on azure
15 map reduce on azurePatrick Bury
 

Plus de Patrick Bury (20)

100 évaluation
100 évaluation100 évaluation
100 évaluation
 
16 graph databases
16 graph databases16 graph databases
16 graph databases
 
15 map reduce on azure
15 map reduce on azure15 map reduce on azure
15 map reduce on azure
 
11 big data aws
11 big data aws11 big data aws
11 big data aws
 
14 big data gitlab
14 big data gitlab14 big data gitlab
14 big data gitlab
 
13 big data docker
13 big data docker13 big data docker
13 big data docker
 
10 big data hadoop
10 big data hadoop10 big data hadoop
10 big data hadoop
 
08 big data dataviz
08 big data dataviz08 big data dataviz
08 big data dataviz
 
12 big data azure
12 big data azure12 big data azure
12 big data azure
 
07 big data sgbd
07 big data sgbd07 big data sgbd
07 big data sgbd
 
06 cloud souverain
06 cloud souverain06 cloud souverain
06 cloud souverain
 
05 creation instance ovh
05 creation instance ovh05 creation instance ovh
05 creation instance ovh
 
04 big data fournisseurs
04 big data fournisseurs04 big data fournisseurs
04 big data fournisseurs
 
03 big data stockage
03 big data stockage03 big data stockage
03 big data stockage
 
03 big data échelle
03 big data échelle03 big data échelle
03 big data échelle
 
02 big data definition
02 big data definition02 big data definition
02 big data definition
 
01 open data
01 open data01 open data
01 open data
 
01 big data introduction
01 big data introduction01 big data introduction
01 big data introduction
 
16 graph databases
16 graph databases16 graph databases
16 graph databases
 
15 map reduce on azure
15 map reduce on azure15 map reduce on azure
15 map reduce on azure
 

Dernier

Guide Final de rédaction de mémoire de fin d'étude
Guide Final de rédaction de mémoire de fin d'étudeGuide Final de rédaction de mémoire de fin d'étude
Guide Final de rédaction de mémoire de fin d'étudeBenamraneMarwa
 
Cours SE Gestion des périphériques - IG IPSET
Cours SE Gestion des périphériques - IG IPSETCours SE Gestion des périphériques - IG IPSET
Cours SE Gestion des périphériques - IG IPSETMedBechir
 
7 PPT sue le project de fin d'étude.pptx
7 PPT sue le project de fin d'étude.pptx7 PPT sue le project de fin d'étude.pptx
7 PPT sue le project de fin d'étude.pptxrababouerdighi
 
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptxSAID MASHATE
 
Saint Georges, martyr, et la lègend du dragon.pptx
Saint Georges, martyr, et la lègend du dragon.pptxSaint Georges, martyr, et la lègend du dragon.pptx
Saint Georges, martyr, et la lègend du dragon.pptxMartin M Flynn
 
A3iFormations, organisme de formations certifié qualiopi.
A3iFormations, organisme de formations certifié qualiopi.A3iFormations, organisme de formations certifié qualiopi.
A3iFormations, organisme de formations certifié qualiopi.Franck Apolis
 
Fondation Louis Vuitton. pptx
Fondation      Louis      Vuitton.   pptxFondation      Louis      Vuitton.   pptx
Fondation Louis Vuitton. pptxTxaruka
 
Présentation_ Didactique 1_SVT (S4) complet.pptx
Présentation_ Didactique 1_SVT (S4) complet.pptxPrésentation_ Didactique 1_SVT (S4) complet.pptx
Présentation_ Didactique 1_SVT (S4) complet.pptxrababouerdighi
 
Annie Ernaux Extérieurs. pptx. Exposition basée sur un livre .
Annie   Ernaux  Extérieurs. pptx. Exposition basée sur un livre .Annie   Ernaux  Extérieurs. pptx. Exposition basée sur un livre .
Annie Ernaux Extérieurs. pptx. Exposition basée sur un livre .Txaruka
 
Formation M2i - Comprendre les neurosciences pour développer son leadership
Formation M2i - Comprendre les neurosciences pour développer son leadershipFormation M2i - Comprendre les neurosciences pour développer son leadership
Formation M2i - Comprendre les neurosciences pour développer son leadershipM2i Formation
 
Evaluation du systeme d'Education. Marocpptx
Evaluation du systeme d'Education. MarocpptxEvaluation du systeme d'Education. Marocpptx
Evaluation du systeme d'Education. MarocpptxAsmaa105193
 
systeme expert_systeme expert_systeme expert
systeme expert_systeme expert_systeme expertsysteme expert_systeme expert_systeme expert
systeme expert_systeme expert_systeme expertChristianMbip
 
Cours SE Le système Linux : La ligne de commande bash - IG IPSET
Cours SE Le système Linux : La ligne de commande bash - IG IPSETCours SE Le système Linux : La ligne de commande bash - IG IPSET
Cours SE Le système Linux : La ligne de commande bash - IG IPSETMedBechir
 

Dernier (15)

Guide Final de rédaction de mémoire de fin d'étude
Guide Final de rédaction de mémoire de fin d'étudeGuide Final de rédaction de mémoire de fin d'étude
Guide Final de rédaction de mémoire de fin d'étude
 
Pâques de Sainte Marie-Euphrasie Pelletier
Pâques de Sainte Marie-Euphrasie PelletierPâques de Sainte Marie-Euphrasie Pelletier
Pâques de Sainte Marie-Euphrasie Pelletier
 
Cours SE Gestion des périphériques - IG IPSET
Cours SE Gestion des périphériques - IG IPSETCours SE Gestion des périphériques - IG IPSET
Cours SE Gestion des périphériques - IG IPSET
 
7 PPT sue le project de fin d'étude.pptx
7 PPT sue le project de fin d'étude.pptx7 PPT sue le project de fin d'étude.pptx
7 PPT sue le project de fin d'étude.pptx
 
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
 
Saint Georges, martyr, et la lègend du dragon.pptx
Saint Georges, martyr, et la lègend du dragon.pptxSaint Georges, martyr, et la lègend du dragon.pptx
Saint Georges, martyr, et la lègend du dragon.pptx
 
A3iFormations, organisme de formations certifié qualiopi.
A3iFormations, organisme de formations certifié qualiopi.A3iFormations, organisme de formations certifié qualiopi.
A3iFormations, organisme de formations certifié qualiopi.
 
Fondation Louis Vuitton. pptx
Fondation      Louis      Vuitton.   pptxFondation      Louis      Vuitton.   pptx
Fondation Louis Vuitton. pptx
 
Présentation_ Didactique 1_SVT (S4) complet.pptx
Présentation_ Didactique 1_SVT (S4) complet.pptxPrésentation_ Didactique 1_SVT (S4) complet.pptx
Présentation_ Didactique 1_SVT (S4) complet.pptx
 
Evaluación Alumnos de Ecole Victor Hugo
Evaluación Alumnos de Ecole  Victor HugoEvaluación Alumnos de Ecole  Victor Hugo
Evaluación Alumnos de Ecole Victor Hugo
 
Annie Ernaux Extérieurs. pptx. Exposition basée sur un livre .
Annie   Ernaux  Extérieurs. pptx. Exposition basée sur un livre .Annie   Ernaux  Extérieurs. pptx. Exposition basée sur un livre .
Annie Ernaux Extérieurs. pptx. Exposition basée sur un livre .
 
Formation M2i - Comprendre les neurosciences pour développer son leadership
Formation M2i - Comprendre les neurosciences pour développer son leadershipFormation M2i - Comprendre les neurosciences pour développer son leadership
Formation M2i - Comprendre les neurosciences pour développer son leadership
 
Evaluation du systeme d'Education. Marocpptx
Evaluation du systeme d'Education. MarocpptxEvaluation du systeme d'Education. Marocpptx
Evaluation du systeme d'Education. Marocpptx
 
systeme expert_systeme expert_systeme expert
systeme expert_systeme expert_systeme expertsysteme expert_systeme expert_systeme expert
systeme expert_systeme expert_systeme expert
 
Cours SE Le système Linux : La ligne de commande bash - IG IPSET
Cours SE Le système Linux : La ligne de commande bash - IG IPSETCours SE Le système Linux : La ligne de commande bash - IG IPSET
Cours SE Le système Linux : La ligne de commande bash - IG IPSET
 

09 big data mapreduce

  • 2. TP1 : Map reduce en python  Le Hello World du Map Reduce : compter les mots  Vous avez à coder plusieurs modules :  Mapper.py  Qui lit un texte sur l’entrée standard  Et qui renvoie un doublet : mot tabulation (t) 1 retour à la ligne (n) sur la sortie standard  Reducer.py  Qui lit les doublets depuis l’entrée standard  Qui calcule le nombre d’occurrence d’un mot 2
  • 3. Résultats attendus 3 echo "foo foo quux labs foo bar quux" | /home/hduser/mapper.py foo 1 foo 1 quux 1 labs 1 foo 1 bar 1 quux 1 echo "foo foo quux labs foo bar quux" | /home/hduser/mapper.py | sort -k1,1 | /home/hduser/reducer.py bar 1 foo 3 labs 1 quux 2
  • 4. Pure Python fonction map 4 map(function_to_apply, list_of_inputs) Cela permet de remplacer un code comme celui-ci item = [1,2,3,4,5] carres = [] for i in items: carres.append(i**2) item = [1,2,3,4,5] Carres = list(map(lambda x: x**2, items)) par
  • 5. Pure Python fonction filter 5 filter(function_to_apply, list_of_inputs) Agit comme une boucle mais c’est une fonction interne, plus rapide liste = range(-5, 5) negatifs = list(filter(lambda x: x<0, liste)) [-5, -4, -3, -2, -1] renvoie
  • 6. Pure Python fonction reduce 6 reduce(function_to_apply, list_of_inputs) Cela permet de remplacer un code comme celui-ci produit = 1 list = [1, 2, 3, 4] for num in list: produit = produit * num from functools import reduce list = [1, 2, 3, 4] produit = reduce((lambda x,y: x*y), list) par
  • 7. Map 7 #!/usr/bin/env python """mapper.py""" import sys # input comes from STDIN (standard input) for line in sys.stdin: # remove leading and trailing whitespace line = line.strip() # split the line into words words = line.split() # increase counters for word in words: # write the results to STDOUT (standard output); # what we output here will be the input for the # Reduce step, i.e. the input for reducer.py # # tab-delimited; the trivial word count is 1 print('%st%s' % (word, 1) )
  • 8. Reduce 8 #!/usr/bin/env python from operator import itemgetter import sys current_word = None current_count = 0 word = None for line in sys.stdin: line = line.strip() word, count = line.split('t', 1) try: count = int(count) except ValueError: # count was not a number, so silently # ignore/discard this line continue if current_word == word: current_count += count else: if current_word: print('%st%s' % (current_word, current_count)) current_count = count current_word = word if current_word == word: print('%st%s' % (current_word, current_count))
  • 9. Pipe (/Paipe/)  Toutes les commandes un*x ont trois moyens de communiquer avec l’utilisateur  Un moyen de lire ce qu’il demande (par défaut par le clavier) : stdin  Un moyen de transmettre des informations (par défaut à l’écran) : stdout  Un moyen de signaler les erreurs (par défaut à l’écran) : stderr  Un*x permet de chainer les commandes  On relie le stdout d’un programme au stdin du suivant  C’est la commande pipe, notée | 9