mapred_tutorial.html 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <meta content="Apache Forrest" name="Generator">
  6. <meta name="Forrest-version" content="0.8">
  7. <meta name="Forrest-skin-name" content="pelt">
  8. <title>Hadoop Map-Reduce Tutorial</title>
  9. <link type="text/css" href="skin/basic.css" rel="stylesheet">
  10. <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
  11. <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
  12. <link type="text/css" href="skin/profile.css" rel="stylesheet">
  13. <script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
  14. <link rel="shortcut icon" href="images/favicon.ico">
  15. </head>
  16. <body onload="init()">
  17. <script type="text/javascript">ndeSetTextSize();</script>
  18. <div id="top">
  19. <!--+
  20. |breadtrail
  21. +-->
  22. <div class="breadtrail">
  23. <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://hadoop.apache.org/">Hadoop</a> &gt; <a href="http://hadoop.apache.org/core/">Core</a><script src="skin/breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
  24. </div>
  25. <!--+
  26. |header
  27. +-->
  28. <div class="header">
  29. <!--+
  30. |start group logo
  31. +-->
  32. <div class="grouplogo">
  33. <a href="http://hadoop.apache.org/"><img class="logoImage" alt="Hadoop" src="images/hadoop-logo.jpg" title="Apache Hadoop"></a>
  34. </div>
  35. <!--+
  36. |end group logo
  37. +-->
  38. <!--+
  39. |start Project Logo
  40. +-->
  41. <div class="projectlogo">
  42. <a href="http://hadoop.apache.org/core/"><img class="logoImage" alt="Hadoop" src="images/core-logo.gif" title="Scalable Computing Platform"></a>
  43. </div>
  44. <!--+
  45. |end Project Logo
  46. +-->
  47. <!--+
  48. |start Search
  49. +-->
  50. <div class="searchbox">
  51. <form action="http://www.google.com/search" method="get" class="roundtopsmall">
  52. <input value="hadoop.apache.org" name="sitesearch" type="hidden"><input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google">&nbsp;
  53. <input name="Search" value="Search" type="submit">
  54. </form>
  55. </div>
  56. <!--+
  57. |end search
  58. +-->
  59. <!--+
  60. |start Tabs
  61. +-->
  62. <ul id="tabs">
  63. <li>
  64. <a class="unselected" href="http://hadoop.apache.org/core/">Project</a>
  65. </li>
  66. <li>
  67. <a class="unselected" href="http://wiki.apache.org/hadoop">Wiki</a>
  68. </li>
  69. <li class="current">
  70. <a class="selected" href="index.html">Hadoop 0.17 Documentation</a>
  71. </li>
  72. </ul>
  73. <!--+
  74. |end Tabs
  75. +-->
  76. </div>
  77. </div>
  78. <div id="main">
  79. <div id="publishedStrip">
  80. <!--+
  81. |start Subtabs
  82. +-->
  83. <div id="level2tabs"></div>
  84. <!--+
  85. |end Endtabs
  86. +-->
  87. <script type="text/javascript"><!--
  88. document.write("Last Published: " + document.lastModified);
  89. // --></script>
  90. </div>
  91. <!--+
  92. |breadtrail
  93. +-->
  94. <div class="breadtrail">
  95. &nbsp;
  96. </div>
  97. <!--+
  98. |start Menu, mainarea
  99. +-->
  100. <!--+
  101. |start Menu
  102. +-->
  103. <div id="menu">
  104. <div onclick="SwitchMenu('menu_selected_1.1', 'skin/')" id="menu_selected_1.1Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Documentation</div>
  105. <div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
  106. <div class="menuitem">
  107. <a href="index.html">Overview</a>
  108. </div>
  109. <div class="menuitem">
  110. <a href="quickstart.html">Quickstart</a>
  111. </div>
  112. <div class="menuitem">
  113. <a href="cluster_setup.html">Cluster Setup</a>
  114. </div>
  115. <div class="menuitem">
  116. <a href="hdfs_design.html">HDFS Architecture</a>
  117. </div>
  118. <div class="menuitem">
  119. <a href="hdfs_user_guide.html">HDFS User Guide</a>
  120. </div>
  121. <div class="menuitem">
  122. <a href="hdfs_shell.html">HDFS Shell Guide</a>
  123. </div>
  124. <div class="menuitem">
  125. <a href="hdfs_permissions_guide.html">HDFS Permissions Guide</a>
  126. </div>
  127. <div class="menupage">
  128. <div class="menupagetitle">Map-Reduce Tutorial</div>
  129. </div>
  130. <div class="menuitem">
  131. <a href="native_libraries.html">Native Hadoop Libraries</a>
  132. </div>
  133. <div class="menuitem">
  134. <a href="streaming.html">Streaming</a>
  135. </div>
  136. <div class="menuitem">
  137. <a href="hod.html">Hadoop On Demand</a>
  138. </div>
  139. <div class="menuitem">
  140. <a href="api/index.html">API Docs</a>
  141. </div>
  142. <div class="menuitem">
  143. <a href="http://wiki.apache.org/hadoop/">Wiki</a>
  144. </div>
  145. <div class="menuitem">
  146. <a href="http://wiki.apache.org/hadoop/FAQ">FAQ</a>
  147. </div>
  148. <div class="menuitem">
  149. <a href="http://hadoop.apache.org/core/mailing_lists.html">Mailing Lists</a>
  150. </div>
  151. <div class="menuitem">
  152. <a href="changes.html">Release Notes</a>
  153. </div>
  154. </div>
  155. <div id="credit"></div>
  156. <div id="roundbottom">
  157. <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
  158. <!--+
  159. |alternative credits
  160. +-->
  161. <div id="credit2"></div>
  162. </div>
  163. <!--+
  164. |end Menu
  165. +-->
  166. <!--+
  167. |start content
  168. +-->
  169. <div id="content">
  170. <div title="Portable Document Format" class="pdflink">
  171. <a class="dida" href="mapred_tutorial.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
  172. PDF</a>
  173. </div>
  174. <h1>Hadoop Map-Reduce Tutorial</h1>
  175. <div id="minitoc-area">
  176. <ul class="minitoc">
  177. <li>
  178. <a href="#Purpose">Purpose</a>
  179. </li>
  180. <li>
  181. <a href="#Pre-requisites">Pre-requisites</a>
  182. </li>
  183. <li>
  184. <a href="#Overview">Overview</a>
  185. </li>
  186. <li>
  187. <a href="#Inputs+and+Outputs">Inputs and Outputs</a>
  188. </li>
  189. <li>
  190. <a href="#Example%3A+WordCount+v1.0">Example: WordCount v1.0</a>
  191. <ul class="minitoc">
  192. <li>
  193. <a href="#Source+Code">Source Code</a>
  194. </li>
  195. <li>
  196. <a href="#Usage">Usage</a>
  197. </li>
  198. <li>
  199. <a href="#Walk-through">Walk-through</a>
  200. </li>
  201. </ul>
  202. </li>
  203. <li>
  204. <a href="#Map-Reduce+-+User+Interfaces">Map-Reduce - User Interfaces</a>
  205. <ul class="minitoc">
  206. <li>
  207. <a href="#Payload">Payload</a>
  208. <ul class="minitoc">
  209. <li>
  210. <a href="#Mapper">Mapper</a>
  211. </li>
  212. <li>
  213. <a href="#Reducer">Reducer</a>
  214. </li>
  215. <li>
  216. <a href="#Partitioner">Partitioner</a>
  217. </li>
  218. <li>
  219. <a href="#Reporter">Reporter</a>
  220. </li>
  221. <li>
  222. <a href="#OutputCollector">OutputCollector</a>
  223. </li>
  224. </ul>
  225. </li>
  226. <li>
  227. <a href="#Job+Configuration">Job Configuration</a>
  228. </li>
  229. <li>
  230. <a href="#Task+Execution+%26+Environment">Task Execution &amp; Environment</a>
  231. </li>
  232. <li>
  233. <a href="#Job+Submission+and+Monitoring">Job Submission and Monitoring</a>
  234. <ul class="minitoc">
  235. <li>
  236. <a href="#Job+Control">Job Control</a>
  237. </li>
  238. </ul>
  239. </li>
  240. <li>
  241. <a href="#Job+Input">Job Input</a>
  242. <ul class="minitoc">
  243. <li>
  244. <a href="#InputSplit">InputSplit</a>
  245. </li>
  246. <li>
  247. <a href="#RecordReader">RecordReader</a>
  248. </li>
  249. </ul>
  250. </li>
  251. <li>
  252. <a href="#Job+Output">Job Output</a>
  253. <ul class="minitoc">
  254. <li>
  255. <a href="#Task+Side-Effect+Files">Task Side-Effect Files</a>
  256. </li>
  257. <li>
  258. <a href="#RecordWriter">RecordWriter</a>
  259. </li>
  260. </ul>
  261. </li>
  262. <li>
  263. <a href="#Other+Useful+Features">Other Useful Features</a>
  264. <ul class="minitoc">
  265. <li>
  266. <a href="#Counters">Counters</a>
  267. </li>
  268. <li>
  269. <a href="#DistributedCache">DistributedCache</a>
  270. </li>
  271. <li>
  272. <a href="#Tool">Tool</a>
  273. </li>
  274. <li>
  275. <a href="#IsolationRunner">IsolationRunner</a>
  276. </li>
  277. <li>
  278. <a href="#Debugging">Debugging</a>
  279. </li>
  280. <li>
  281. <a href="#JobControl">JobControl</a>
  282. </li>
  283. <li>
  284. <a href="#Data+Compression">Data Compression</a>
  285. </li>
  286. </ul>
  287. </li>
  288. </ul>
  289. </li>
  290. <li>
  291. <a href="#Example%3A+WordCount+v2.0">Example: WordCount v2.0</a>
  292. <ul class="minitoc">
  293. <li>
  294. <a href="#Source+Code-N10C76">Source Code</a>
  295. </li>
  296. <li>
  297. <a href="#Sample+Runs">Sample Runs</a>
  298. </li>
  299. <li>
  300. <a href="#Highlights">Highlights</a>
  301. </li>
  302. </ul>
  303. </li>
  304. </ul>
  305. </div>
  306. <a name="N1000D"></a><a name="Purpose"></a>
  307. <h2 class="h3">Purpose</h2>
  308. <div class="section">
  309. <p>This document comprehensively describes all user-facing facets of the
  310. Hadoop Map-Reduce framework and serves as a tutorial.
  311. </p>
  312. </div>
  313. <a name="N10017"></a><a name="Pre-requisites"></a>
  314. <h2 class="h3">Pre-requisites</h2>
  315. <div class="section">
  316. <p>Ensure that Hadoop is installed, configured and is running. More
  317. details:</p>
  318. <ul>
  319. <li>
  320. Hadoop <a href="quickstart.html">Quickstart</a> for first-time users.
  321. </li>
  322. <li>
  323. Hadoop <a href="cluster_setup.html">Cluster Setup</a> for large,
  324. distributed clusters.
  325. </li>
  326. </ul>
  327. </div>
  328. <a name="N10032"></a><a name="Overview"></a>
  329. <h2 class="h3">Overview</h2>
  330. <div class="section">
  331. <p>Hadoop Map-Reduce is a software framework for easily writing
  332. applications which process vast amounts of data (multi-terabyte data-sets)
  333. in-parallel on large clusters (thousands of nodes) of commodity
  334. hardware in a reliable, fault-tolerant manner.</p>
  335. <p>A Map-Reduce <em>job</em> usually splits the input data-set into
  336. independent chunks which are processed by the <em>map tasks</em> in a
  337. completely parallel manner. The framework sorts the outputs of the maps,
  338. which are then input to the <em>reduce tasks</em>. Typically both the
  339. input and the output of the job are stored in a file-system. The framework
  340. takes care of scheduling tasks, monitoring them and re-executes the failed
  341. tasks.</p>
  342. <p>Typically the compute nodes and the storage nodes are the same, that is,
  343. the Map-Reduce framework and the <a href="hdfs_design.html">Distributed
  344. FileSystem</a> are running on the same set of nodes. This configuration
  345. allows the framework to effectively schedule tasks on the nodes where data
  346. is already present, resulting in very high aggregate bandwidth across the
  347. cluster.</p>
  348. <p>The Map-Reduce framework consists of a single master
  349. <span class="codefrag">JobTracker</span> and one slave <span class="codefrag">TaskTracker</span> per
  350. cluster-node. The master is responsible for scheduling the jobs' component
  351. tasks on the slaves, monitoring them and re-executing the failed tasks. The
  352. slaves execute the tasks as directed by the master.</p>
  353. <p>Minimally, applications specify the input/output locations and supply
  354. <em>map</em> and <em>reduce</em> functions via implementations of
  355. appropriate interfaces and/or abstract-classes. These, and other job
  356. parameters, comprise the <em>job configuration</em>. The Hadoop
  357. <em>job client</em> then submits the job (jar/executable etc.) and
  358. configuration to the <span class="codefrag">JobTracker</span> which then assumes the
  359. responsibility of distributing the software/configuration to the slaves,
  360. scheduling tasks and monitoring them, providing status and diagnostic
  361. information to the job-client.</p>
  362. <p>Although the Hadoop framework is implemented in Java<sup>TM</sup>,
  363. Map-Reduce applications need not be written in Java.</p>
  364. <ul>
  365. <li>
  366. <a href="api/org/apache/hadoop/streaming/package-summary.html">
  367. Hadoop Streaming</a> is a utility which allows users to create and run
  368. jobs with any executables (e.g. shell utilities) as the mapper and/or
  369. the reducer.
  370. </li>
  371. <li>
  372. <a href="api/org/apache/hadoop/mapred/pipes/package-summary.html">
  373. Hadoop Pipes</a> is a <a href="http://www.swig.org/">SWIG</a>-
  374. compatible <em>C++ API</em> to implement Map-Reduce applications (non
  375. JNI<sup>TM</sup> based).
  376. </li>
  377. </ul>
  378. </div>
  379. <a name="N1008B"></a><a name="Inputs+and+Outputs"></a>
  380. <h2 class="h3">Inputs and Outputs</h2>
  381. <div class="section">
  382. <p>The Map-Reduce framework operates exclusively on
  383. <span class="codefrag">&lt;key, value&gt;</span> pairs, that is, the framework views the
  384. input to the job as a set of <span class="codefrag">&lt;key, value&gt;</span> pairs and
  385. produces a set of <span class="codefrag">&lt;key, value&gt;</span> pairs as the output of
  386. the job, conceivably of different types.</p>
  387. <p>The <span class="codefrag">key</span> and <span class="codefrag">value</span> classes have to be
  388. serializable by the framework and hence need to implement the
  389. <a href="api/org/apache/hadoop/io/Writable.html">Writable</a>
  390. interface. Additionally, the <span class="codefrag">key</span> classes have to implement the
  391. <a href="api/org/apache/hadoop/io/WritableComparable.html">
  392. WritableComparable</a> interface to facilitate sorting by the framework.
  393. </p>
  394. <p>Input and Output types of a Map-Reduce job:</p>
  395. <p>
  396. (input) <span class="codefrag">&lt;k1, v1&gt;</span>
  397. -&gt;
  398. <strong>map</strong>
  399. -&gt;
  400. <span class="codefrag">&lt;k2, v2&gt;</span>
  401. -&gt;
  402. <strong>combine</strong>
  403. -&gt;
  404. <span class="codefrag">&lt;k2, v2&gt;</span>
  405. -&gt;
  406. <strong>reduce</strong>
  407. -&gt;
  408. <span class="codefrag">&lt;k3, v3&gt;</span> (output)
  409. </p>
  410. </div>
  411. <a name="N100CD"></a><a name="Example%3A+WordCount+v1.0"></a>
  412. <h2 class="h3">Example: WordCount v1.0</h2>
  413. <div class="section">
  414. <p>Before we jump into the details, lets walk through an example Map-Reduce
  415. application to get a flavour for how they work.</p>
  416. <p>
  417. <span class="codefrag">WordCount</span> is a simple application that counts the number of
  418. occurences of each word in a given input set.</p>
  419. <p>This works with a
  420. <a href="quickstart.html#Standalone+Operation">local-standalone</a>,
  421. <a href="quickstart.html#SingleNodeSetup">pseudo-distributed</a> or
  422. <a href="quickstart.html#Fully-Distributed+Operation">fully-distributed</a>
  423. Hadoop installation.</p>
  424. <a name="N100EA"></a><a name="Source+Code"></a>
  425. <h3 class="h4">Source Code</h3>
  426. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  427. <tr>
  428. <th colspan="1" rowspan="1"></th>
  429. <th colspan="1" rowspan="1">WordCount.java</th>
  430. </tr>
  431. <tr>
  432. <td colspan="1" rowspan="1">1.</td>
  433. <td colspan="1" rowspan="1">
  434. <span class="codefrag">package org.myorg;</span>
  435. </td>
  436. </tr>
  437. <tr>
  438. <td colspan="1" rowspan="1">2.</td>
  439. <td colspan="1" rowspan="1"></td>
  440. </tr>
  441. <tr>
  442. <td colspan="1" rowspan="1">3.</td>
  443. <td colspan="1" rowspan="1">
  444. <span class="codefrag">import java.io.IOException;</span>
  445. </td>
  446. </tr>
  447. <tr>
  448. <td colspan="1" rowspan="1">4.</td>
  449. <td colspan="1" rowspan="1">
  450. <span class="codefrag">import java.util.*;</span>
  451. </td>
  452. </tr>
  453. <tr>
  454. <td colspan="1" rowspan="1">5.</td>
  455. <td colspan="1" rowspan="1"></td>
  456. </tr>
  457. <tr>
  458. <td colspan="1" rowspan="1">6.</td>
  459. <td colspan="1" rowspan="1">
  460. <span class="codefrag">import org.apache.hadoop.fs.Path;</span>
  461. </td>
  462. </tr>
  463. <tr>
  464. <td colspan="1" rowspan="1">7.</td>
  465. <td colspan="1" rowspan="1">
  466. <span class="codefrag">import org.apache.hadoop.conf.*;</span>
  467. </td>
  468. </tr>
  469. <tr>
  470. <td colspan="1" rowspan="1">8.</td>
  471. <td colspan="1" rowspan="1">
  472. <span class="codefrag">import org.apache.hadoop.io.*;</span>
  473. </td>
  474. </tr>
  475. <tr>
  476. <td colspan="1" rowspan="1">9.</td>
  477. <td colspan="1" rowspan="1">
  478. <span class="codefrag">import org.apache.hadoop.mapred.*;</span>
  479. </td>
  480. </tr>
  481. <tr>
  482. <td colspan="1" rowspan="1">10.</td>
  483. <td colspan="1" rowspan="1">
  484. <span class="codefrag">import org.apache.hadoop.util.*;</span>
  485. </td>
  486. </tr>
  487. <tr>
  488. <td colspan="1" rowspan="1">11.</td>
  489. <td colspan="1" rowspan="1"></td>
  490. </tr>
  491. <tr>
  492. <td colspan="1" rowspan="1">12.</td>
  493. <td colspan="1" rowspan="1">
  494. <span class="codefrag">public class WordCount {</span>
  495. </td>
  496. </tr>
  497. <tr>
  498. <td colspan="1" rowspan="1">13.</td>
  499. <td colspan="1" rowspan="1"></td>
  500. </tr>
  501. <tr>
  502. <td colspan="1" rowspan="1">14.</td>
  503. <td colspan="1" rowspan="1">
  504. &nbsp;&nbsp;
  505. <span class="codefrag">
  506. public static class Map extends MapReduceBase
  507. implements Mapper&lt;LongWritable, Text, Text, IntWritable&gt; {
  508. </span>
  509. </td>
  510. </tr>
  511. <tr>
  512. <td colspan="1" rowspan="1">15.</td>
  513. <td colspan="1" rowspan="1">
  514. &nbsp;&nbsp;&nbsp;&nbsp;
  515. <span class="codefrag">
  516. private final static IntWritable one = new IntWritable(1);
  517. </span>
  518. </td>
  519. </tr>
  520. <tr>
  521. <td colspan="1" rowspan="1">16.</td>
  522. <td colspan="1" rowspan="1">
  523. &nbsp;&nbsp;&nbsp;&nbsp;
  524. <span class="codefrag">private Text word = new Text();</span>
  525. </td>
  526. </tr>
  527. <tr>
  528. <td colspan="1" rowspan="1">17.</td>
  529. <td colspan="1" rowspan="1"></td>
  530. </tr>
  531. <tr>
  532. <td colspan="1" rowspan="1">18.</td>
  533. <td colspan="1" rowspan="1">
  534. &nbsp;&nbsp;&nbsp;&nbsp;
  535. <span class="codefrag">
  536. public void map(LongWritable key, Text value,
  537. OutputCollector&lt;Text, IntWritable&gt; output,
  538. Reporter reporter) throws IOException {
  539. </span>
  540. </td>
  541. </tr>
  542. <tr>
  543. <td colspan="1" rowspan="1">19.</td>
  544. <td colspan="1" rowspan="1">
  545. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  546. <span class="codefrag">String line = value.toString();</span>
  547. </td>
  548. </tr>
  549. <tr>
  550. <td colspan="1" rowspan="1">20.</td>
  551. <td colspan="1" rowspan="1">
  552. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  553. <span class="codefrag">StringTokenizer tokenizer = new StringTokenizer(line);</span>
  554. </td>
  555. </tr>
  556. <tr>
  557. <td colspan="1" rowspan="1">21.</td>
  558. <td colspan="1" rowspan="1">
  559. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  560. <span class="codefrag">while (tokenizer.hasMoreTokens()) {</span>
  561. </td>
  562. </tr>
  563. <tr>
  564. <td colspan="1" rowspan="1">22.</td>
  565. <td colspan="1" rowspan="1">
  566. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  567. <span class="codefrag">word.set(tokenizer.nextToken());</span>
  568. </td>
  569. </tr>
  570. <tr>
  571. <td colspan="1" rowspan="1">23.</td>
  572. <td colspan="1" rowspan="1">
  573. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  574. <span class="codefrag">output.collect(word, one);</span>
  575. </td>
  576. </tr>
  577. <tr>
  578. <td colspan="1" rowspan="1">24.</td>
  579. <td colspan="1" rowspan="1">
  580. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  581. <span class="codefrag">}</span>
  582. </td>
  583. </tr>
  584. <tr>
  585. <td colspan="1" rowspan="1">25.</td>
  586. <td colspan="1" rowspan="1">
  587. &nbsp;&nbsp;&nbsp;&nbsp;
  588. <span class="codefrag">}</span>
  589. </td>
  590. </tr>
  591. <tr>
  592. <td colspan="1" rowspan="1">26.</td>
  593. <td colspan="1" rowspan="1">
  594. &nbsp;&nbsp;
  595. <span class="codefrag">}</span>
  596. </td>
  597. </tr>
  598. <tr>
  599. <td colspan="1" rowspan="1">27.</td>
  600. <td colspan="1" rowspan="1"></td>
  601. </tr>
  602. <tr>
  603. <td colspan="1" rowspan="1">28.</td>
  604. <td colspan="1" rowspan="1">
  605. &nbsp;&nbsp;
  606. <span class="codefrag">
  607. public static class Reduce extends MapReduceBase implements
  608. Reducer&lt;Text, IntWritable, Text, IntWritable&gt; {
  609. </span>
  610. </td>
  611. </tr>
  612. <tr>
  613. <td colspan="1" rowspan="1">29.</td>
  614. <td colspan="1" rowspan="1">
  615. &nbsp;&nbsp;&nbsp;&nbsp;
  616. <span class="codefrag">
  617. public void reduce(Text key, Iterator&lt;IntWritable&gt; values,
  618. OutputCollector&lt;Text, IntWritable&gt; output,
  619. Reporter reporter) throws IOException {
  620. </span>
  621. </td>
  622. </tr>
  623. <tr>
  624. <td colspan="1" rowspan="1">30.</td>
  625. <td colspan="1" rowspan="1">
  626. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  627. <span class="codefrag">int sum = 0;</span>
  628. </td>
  629. </tr>
  630. <tr>
  631. <td colspan="1" rowspan="1">31.</td>
  632. <td colspan="1" rowspan="1">
  633. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  634. <span class="codefrag">while (values.hasNext()) {</span>
  635. </td>
  636. </tr>
  637. <tr>
  638. <td colspan="1" rowspan="1">32.</td>
  639. <td colspan="1" rowspan="1">
  640. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  641. <span class="codefrag">sum += values.next().get();</span>
  642. </td>
  643. </tr>
  644. <tr>
  645. <td colspan="1" rowspan="1">33.</td>
  646. <td colspan="1" rowspan="1">
  647. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  648. <span class="codefrag">}</span>
  649. </td>
  650. </tr>
  651. <tr>
  652. <td colspan="1" rowspan="1">34.</td>
  653. <td colspan="1" rowspan="1">
  654. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  655. <span class="codefrag">output.collect(key, new IntWritable(sum));</span>
  656. </td>
  657. </tr>
  658. <tr>
  659. <td colspan="1" rowspan="1">35.</td>
  660. <td colspan="1" rowspan="1">
  661. &nbsp;&nbsp;&nbsp;&nbsp;
  662. <span class="codefrag">}</span>
  663. </td>
  664. </tr>
  665. <tr>
  666. <td colspan="1" rowspan="1">36.</td>
  667. <td colspan="1" rowspan="1">
  668. &nbsp;&nbsp;
  669. <span class="codefrag">}</span>
  670. </td>
  671. </tr>
  672. <tr>
  673. <td colspan="1" rowspan="1">37.</td>
  674. <td colspan="1" rowspan="1"></td>
  675. </tr>
  676. <tr>
  677. <td colspan="1" rowspan="1">38.</td>
  678. <td colspan="1" rowspan="1">
  679. &nbsp;&nbsp;
  680. <span class="codefrag">
  681. public static void main(String[] args) throws Exception {
  682. </span>
  683. </td>
  684. </tr>
  685. <tr>
  686. <td colspan="1" rowspan="1">39.</td>
  687. <td colspan="1" rowspan="1">
  688. &nbsp;&nbsp;&nbsp;&nbsp;
  689. <span class="codefrag">
  690. JobConf conf = new JobConf(WordCount.class);
  691. </span>
  692. </td>
  693. </tr>
  694. <tr>
  695. <td colspan="1" rowspan="1">40.</td>
  696. <td colspan="1" rowspan="1">
  697. &nbsp;&nbsp;&nbsp;&nbsp;
  698. <span class="codefrag">conf.setJobName("wordcount");</span>
  699. </td>
  700. </tr>
  701. <tr>
  702. <td colspan="1" rowspan="1">41.</td>
  703. <td colspan="1" rowspan="1"></td>
  704. </tr>
  705. <tr>
  706. <td colspan="1" rowspan="1">42.</td>
  707. <td colspan="1" rowspan="1">
  708. &nbsp;&nbsp;&nbsp;&nbsp;
  709. <span class="codefrag">conf.setOutputKeyClass(Text.class);</span>
  710. </td>
  711. </tr>
  712. <tr>
  713. <td colspan="1" rowspan="1">43.</td>
  714. <td colspan="1" rowspan="1">
  715. &nbsp;&nbsp;&nbsp;&nbsp;
  716. <span class="codefrag">conf.setOutputValueClass(IntWritable.class);</span>
  717. </td>
  718. </tr>
  719. <tr>
  720. <td colspan="1" rowspan="1">44.</td>
  721. <td colspan="1" rowspan="1"></td>
  722. </tr>
  723. <tr>
  724. <td colspan="1" rowspan="1">45.</td>
  725. <td colspan="1" rowspan="1">
  726. &nbsp;&nbsp;&nbsp;&nbsp;
  727. <span class="codefrag">conf.setMapperClass(Map.class);</span>
  728. </td>
  729. </tr>
  730. <tr>
  731. <td colspan="1" rowspan="1">46.</td>
  732. <td colspan="1" rowspan="1">
  733. &nbsp;&nbsp;&nbsp;&nbsp;
  734. <span class="codefrag">conf.setCombinerClass(Reduce.class);</span>
  735. </td>
  736. </tr>
  737. <tr>
  738. <td colspan="1" rowspan="1">47.</td>
  739. <td colspan="1" rowspan="1">
  740. &nbsp;&nbsp;&nbsp;&nbsp;
  741. <span class="codefrag">conf.setReducerClass(Reduce.class);</span>
  742. </td>
  743. </tr>
  744. <tr>
  745. <td colspan="1" rowspan="1">48.</td>
  746. <td colspan="1" rowspan="1"></td>
  747. </tr>
  748. <tr>
  749. <td colspan="1" rowspan="1">49.</td>
  750. <td colspan="1" rowspan="1">
  751. &nbsp;&nbsp;&nbsp;&nbsp;
  752. <span class="codefrag">conf.setInputFormat(TextInputFormat.class);</span>
  753. </td>
  754. </tr>
  755. <tr>
  756. <td colspan="1" rowspan="1">50.</td>
  757. <td colspan="1" rowspan="1">
  758. &nbsp;&nbsp;&nbsp;&nbsp;
  759. <span class="codefrag">conf.setOutputFormat(TextOutputFormat.class);</span>
  760. </td>
  761. </tr>
  762. <tr>
  763. <td colspan="1" rowspan="1">51.</td>
  764. <td colspan="1" rowspan="1"></td>
  765. </tr>
  766. <tr>
  767. <td colspan="1" rowspan="1">52.</td>
  768. <td colspan="1" rowspan="1">
  769. &nbsp;&nbsp;&nbsp;&nbsp;
  770. <span class="codefrag">conf.setInputPath(new Path(args[0]));</span>
  771. </td>
  772. </tr>
  773. <tr>
  774. <td colspan="1" rowspan="1">53.</td>
  775. <td colspan="1" rowspan="1">
  776. &nbsp;&nbsp;&nbsp;&nbsp;
  777. <span class="codefrag">FileOutputFormat.setOutputPath(conf, new Path(args[1]));</span>
  778. </td>
  779. </tr>
  780. <tr>
  781. <td colspan="1" rowspan="1">54.</td>
  782. <td colspan="1" rowspan="1"></td>
  783. </tr>
  784. <tr>
  785. <td colspan="1" rowspan="1">55.</td>
  786. <td colspan="1" rowspan="1">
  787. &nbsp;&nbsp;&nbsp;&nbsp;
  788. <span class="codefrag">JobClient.runJob(conf);</span>
  789. </td>
  790. </tr>
  791. <tr>
  792. <td colspan="1" rowspan="1">57.</td>
  793. <td colspan="1" rowspan="1">
  794. &nbsp;&nbsp;
  795. <span class="codefrag">}</span>
  796. </td>
  797. </tr>
  798. <tr>
  799. <td colspan="1" rowspan="1">58.</td>
  800. <td colspan="1" rowspan="1">
  801. <span class="codefrag">}</span>
  802. </td>
  803. </tr>
  804. <tr>
  805. <td colspan="1" rowspan="1">59.</td>
  806. <td colspan="1" rowspan="1"></td>
  807. </tr>
  808. </table>
  809. <a name="N1046C"></a><a name="Usage"></a>
  810. <h3 class="h4">Usage</h3>
  811. <p>Assuming <span class="codefrag">HADOOP_HOME</span> is the root of the installation and
  812. <span class="codefrag">HADOOP_VERSION</span> is the Hadoop version installed, compile
  813. <span class="codefrag">WordCount.java</span> and create a jar:</p>
  814. <p>
  815. <span class="codefrag">$ mkdir wordcount_classes</span>
  816. <br>
  817. <span class="codefrag">
  818. $ javac -classpath ${HADOOP_HOME}/hadoop-${HADOOP_VERSION}-core.jar
  819. -d wordcount_classes WordCount.java
  820. </span>
  821. <br>
  822. <span class="codefrag">$ jar -cvf /usr/joe/wordcount.jar -C wordcount_classes/ .</span>
  823. </p>
  824. <p>Assuming that:</p>
  825. <ul>
  826. <li>
  827. <span class="codefrag">/usr/joe/wordcount/input</span> - input directory in HDFS
  828. </li>
  829. <li>
  830. <span class="codefrag">/usr/joe/wordcount/output</span> - output directory in HDFS
  831. </li>
  832. </ul>
  833. <p>Sample text-files as input:</p>
  834. <p>
  835. <span class="codefrag">$ bin/hadoop dfs -ls /usr/joe/wordcount/input/</span>
  836. <br>
  837. <span class="codefrag">/usr/joe/wordcount/input/file01</span>
  838. <br>
  839. <span class="codefrag">/usr/joe/wordcount/input/file02</span>
  840. <br>
  841. <br>
  842. <span class="codefrag">$ bin/hadoop dfs -cat /usr/joe/wordcount/input/file01</span>
  843. <br>
  844. <span class="codefrag">Hello World Bye World</span>
  845. <br>
  846. <br>
  847. <span class="codefrag">$ bin/hadoop dfs -cat /usr/joe/wordcount/input/file02</span>
  848. <br>
  849. <span class="codefrag">Hello Hadoop Goodbye Hadoop</span>
  850. </p>
  851. <p>Run the application:</p>
  852. <p>
  853. <span class="codefrag">
  854. $ bin/hadoop jar /usr/joe/wordcount.jar org.myorg.WordCount
  855. /usr/joe/wordcount/input /usr/joe/wordcount/output
  856. </span>
  857. </p>
  858. <p>Output:</p>
  859. <p>
  860. <span class="codefrag">
  861. $ bin/hadoop dfs -cat /usr/joe/wordcount/output/part-00000
  862. </span>
  863. <br>
  864. <span class="codefrag">Bye 1</span>
  865. <br>
  866. <span class="codefrag">Goodbye 1</span>
  867. <br>
  868. <span class="codefrag">Hadoop 2</span>
  869. <br>
  870. <span class="codefrag">Hello 2</span>
  871. <br>
  872. <span class="codefrag">World 2</span>
  873. <br>
  874. </p>
  875. <a name="N104EC"></a><a name="Walk-through"></a>
  876. <h3 class="h4">Walk-through</h3>
  877. <p>The <span class="codefrag">WordCount</span> application is quite straight-forward.</p>
  878. <p>The <span class="codefrag">Mapper</span> implementation (lines 14-26), via the
  879. <span class="codefrag">map</span> method (lines 18-25), processes one line at a time,
  880. as provided by the specified <span class="codefrag">TextInputFormat</span> (line 49).
  881. It then splits the line into tokens separated by whitespaces, via the
  882. <span class="codefrag">StringTokenizer</span>, and emits a key-value pair of
  883. <span class="codefrag">&lt; &lt;word&gt;, 1&gt;</span>.</p>
  884. <p>
  885. For the given sample input the first map emits:<br>
  886. <span class="codefrag">&lt; Hello, 1&gt;</span>
  887. <br>
  888. <span class="codefrag">&lt; World, 1&gt;</span>
  889. <br>
  890. <span class="codefrag">&lt; Bye, 1&gt;</span>
  891. <br>
  892. <span class="codefrag">&lt; World, 1&gt;</span>
  893. <br>
  894. </p>
  895. <p>
  896. The second map emits:<br>
  897. <span class="codefrag">&lt; Hello, 1&gt;</span>
  898. <br>
  899. <span class="codefrag">&lt; Hadoop, 1&gt;</span>
  900. <br>
  901. <span class="codefrag">&lt; Goodbye, 1&gt;</span>
  902. <br>
  903. <span class="codefrag">&lt; Hadoop, 1&gt;</span>
  904. <br>
  905. </p>
  906. <p>We'll learn more about the number of maps spawned for a given job, and
  907. how to control them in a fine-grained manner, a bit later in the
  908. tutorial.</p>
  909. <p>
  910. <span class="codefrag">WordCount</span> also specifies a <span class="codefrag">combiner</span> (line
  911. 46). Hence, the output of each map is passed through the local combiner
  912. (which is same as the <span class="codefrag">Reducer</span> as per the job
  913. configuration) for local aggregation, after being sorted on the
  914. <em>key</em>s.</p>
  915. <p>
  916. The output of the first map:<br>
  917. <span class="codefrag">&lt; Bye, 1&gt;</span>
  918. <br>
  919. <span class="codefrag">&lt; Hello, 1&gt;</span>
  920. <br>
  921. <span class="codefrag">&lt; World, 2&gt;</span>
  922. <br>
  923. </p>
  924. <p>
  925. The output of the second map:<br>
  926. <span class="codefrag">&lt; Goodbye, 1&gt;</span>
  927. <br>
  928. <span class="codefrag">&lt; Hadoop, 2&gt;</span>
  929. <br>
  930. <span class="codefrag">&lt; Hello, 1&gt;</span>
  931. <br>
  932. </p>
  933. <p>The <span class="codefrag">Reducer</span> implementation (lines 28-36), via the
  934. <span class="codefrag">reduce</span> method (lines 29-35) just sums up the values,
  935. which are the occurence counts for each key (i.e. words in this example).
  936. </p>
  937. <p>
  938. Thus the output of the job is:<br>
  939. <span class="codefrag">&lt; Bye, 1&gt;</span>
  940. <br>
  941. <span class="codefrag">&lt; Goodbye, 1&gt;</span>
  942. <br>
  943. <span class="codefrag">&lt; Hadoop, 2&gt;</span>
  944. <br>
  945. <span class="codefrag">&lt; Hello, 2&gt;</span>
  946. <br>
  947. <span class="codefrag">&lt; World, 2&gt;</span>
  948. <br>
  949. </p>
  950. <p>The <span class="codefrag">run</span> method specifies various facets of the job, such
  951. as the input/output paths (passed via the command line), key/value
  952. types, input/output formats etc., in the <span class="codefrag">JobConf</span>.
  953. It then calls the <span class="codefrag">JobClient.runJob</span> (line 55) to submit the
  954. and monitor its progress.</p>
  955. <p>We'll learn more about <span class="codefrag">JobConf</span>, <span class="codefrag">JobClient</span>,
  956. <span class="codefrag">Tool</span> and other interfaces and classes a bit later in the
  957. tutorial.</p>
  958. </div>
  959. <a name="N105A3"></a><a name="Map-Reduce+-+User+Interfaces"></a>
  960. <h2 class="h3">Map-Reduce - User Interfaces</h2>
  961. <div class="section">
  962. <p>This section provides a reasonable amount of detail on every user-facing
  963. aspect of the Map-Reduce framwork. This should help users implement,
  964. configure and tune their jobs in a fine-grained manner. However, please
  965. note that the javadoc for each class/interface remains the most
  966. comprehensive documentation available; this is only meant to be a tutorial.
  967. </p>
  968. <p>Let us first take the <span class="codefrag">Mapper</span> and <span class="codefrag">Reducer</span>
  969. interfaces. Applications typically implement them to provide the
  970. <span class="codefrag">map</span> and <span class="codefrag">reduce</span> methods.</p>
  971. <p>We will then discuss other core interfaces including
  972. <span class="codefrag">JobConf</span>, <span class="codefrag">JobClient</span>, <span class="codefrag">Partitioner</span>,
  973. <span class="codefrag">OutputCollector</span>, <span class="codefrag">Reporter</span>,
  974. <span class="codefrag">InputFormat</span>, <span class="codefrag">OutputFormat</span> and others.</p>
  975. <p>Finally, we will wrap up by discussing some useful features of the
  976. framework such as the <span class="codefrag">DistributedCache</span>,
  977. <span class="codefrag">IsolationRunner</span> etc.</p>
  978. <a name="N105DC"></a><a name="Payload"></a>
  979. <h3 class="h4">Payload</h3>
  980. <p>Applications typically implement the <span class="codefrag">Mapper</span> and
  981. <span class="codefrag">Reducer</span> interfaces to provide the <span class="codefrag">map</span> and
  982. <span class="codefrag">reduce</span> methods. These form the core of the job.</p>
  983. <a name="N105F1"></a><a name="Mapper"></a>
  984. <h4>Mapper</h4>
  985. <p>
  986. <a href="api/org/apache/hadoop/mapred/Mapper.html">
  987. Mapper</a> maps input key/value pairs to a set of intermediate
  988. key/value pairs.</p>
  989. <p>Maps are the individual tasks that transform input records into
  990. intermediate records. The transformed intermediate records do not need
  991. to be of the same type as the input records. A given input pair may
  992. map to zero or many output pairs.</p>
  993. <p>The Hadoop Map-Reduce framework spawns one map task for each
  994. <span class="codefrag">InputSplit</span> generated by the <span class="codefrag">InputFormat</span> for
  995. the job.</p>
  996. <p>Overall, <span class="codefrag">Mapper</span> implementations are passed the
  997. <span class="codefrag">JobConf</span> for the job via the
  998. <a href="api/org/apache/hadoop/mapred/JobConfigurable.html#configure(org.apache.hadoop.mapred.JobConf)">
  999. JobConfigurable.configure(JobConf)</a> method and override it to
  1000. initialize themselves. The framework then calls
  1001. <a href="api/org/apache/hadoop/mapred/Mapper.html#map(K1, V1, org.apache.hadoop.mapred.OutputCollector, org.apache.hadoop.mapred.Reporter)">
  1002. map(WritableComparable, Writable, OutputCollector, Reporter)</a> for
  1003. each key/value pair in the <span class="codefrag">InputSplit</span> for that task.
  1004. Applications can then override the
  1005. <a href="api/org/apache/hadoop/io/Closeable.html#close()">
  1006. Closeable.close()</a> method to perform any required cleanup.</p>
  1007. <p>Output pairs do not need to be of the same types as input pairs. A
  1008. given input pair may map to zero or many output pairs. Output pairs
  1009. are collected with calls to
  1010. <a href="api/org/apache/hadoop/mapred/OutputCollector.html#collect(K, V)">
  1011. OutputCollector.collect(WritableComparable,Writable)</a>.</p>
  1012. <p>Applications can use the <span class="codefrag">Reporter</span> to report
  1013. progress, set application-level status messages and update
  1014. <span class="codefrag">Counters</span>, or just indicate that they are alive.</p>
  1015. <p>All intermediate values associated with a given output key are
  1016. subsequently grouped by the framework, and passed to the
  1017. <span class="codefrag">Reducer</span>(s) to determine the final output. Users can
  1018. control the grouping by specifying a <span class="codefrag">Comparator</span> via
  1019. <a href="api/org/apache/hadoop/mapred/JobConf.html#setOutputKeyComparatorClass(java.lang.Class)">
  1020. JobConf.setOutputKeyComparatorClass(Class)</a>.</p>
  1021. <p>The <span class="codefrag">Mapper</span> outputs are sorted and then
  1022. partitioned per <span class="codefrag">Reducer</span>. The total number of partitions is
  1023. the same as the number of reduce tasks for the job. Users can control
  1024. which keys (and hence records) go to which <span class="codefrag">Reducer</span> by
  1025. implementing a custom <span class="codefrag">Partitioner</span>.</p>
  1026. <p>Users can optionally specify a <span class="codefrag">combiner</span>, via
  1027. <a href="api/org/apache/hadoop/mapred/JobConf.html#setCombinerClass(java.lang.Class)">
  1028. JobConf.setCombinerClass(Class)</a>, to perform local aggregation of
  1029. the intermediate outputs, which helps to cut down the amount of data
  1030. transferred from the <span class="codefrag">Mapper</span> to the <span class="codefrag">Reducer</span>.
  1031. </p>
  1032. <p>The intermediate, sorted outputs are always stored in files of
  1033. <a href="api/org/apache/hadoop/io/SequenceFile.html">
  1034. SequenceFile</a> format. Applications can control if, and how, the
  1035. intermediate outputs are to be compressed and the
  1036. <a href="api/org/apache/hadoop/io/compress/CompressionCodec.html">
  1037. CompressionCodec</a> to be used via the <span class="codefrag">JobConf</span>.
  1038. </p>
  1039. <a name="N1066B"></a><a name="How+Many+Maps%3F"></a>
  1040. <h5>How Many Maps?</h5>
  1041. <p>The number of maps is usually driven by the total size of the
  1042. inputs, that is, the total number of blocks of the input files.</p>
  1043. <p>The right level of parallelism for maps seems to be around 10-100
  1044. maps per-node, although it has been set up to 300 maps for very
  1045. cpu-light map tasks. Task setup takes awhile, so it is best if the
  1046. maps take at least a minute to execute.</p>
  1047. <p>Thus, if you expect 10TB of input data and have a blocksize of
  1048. <span class="codefrag">128MB</span>, you'll end up with 82,000 maps, unless
  1049. <a href="api/org/apache/hadoop/mapred/JobConf.html#setNumMapTasks(int)">
  1050. setNumMapTasks(int)</a> (which only provides a hint to the framework)
  1051. is used to set it even higher.</p>
  1052. <a name="N10683"></a><a name="Reducer"></a>
  1053. <h4>Reducer</h4>
  1054. <p>
  1055. <a href="api/org/apache/hadoop/mapred/Reducer.html">
  1056. Reducer</a> reduces a set of intermediate values which share a key to
  1057. a smaller set of values.</p>
  1058. <p>The number of reduces for the job is set by the user
  1059. via <a href="api/org/apache/hadoop/mapred/JobConf.html#setNumReduceTasks(int)">
  1060. JobConf.setNumReduceTasks(int)</a>.</p>
  1061. <p>Overall, <span class="codefrag">Reducer</span> implementations are passed the
  1062. <span class="codefrag">JobConf</span> for the job via the
  1063. <a href="api/org/apache/hadoop/mapred/JobConfigurable.html#configure(org.apache.hadoop.mapred.JobConf)">
  1064. JobConfigurable.configure(JobConf)</a> method and can override it to
  1065. initialize themselves. The framework then calls
  1066. <a href="api/org/apache/hadoop/mapred/Reducer.html#reduce(K2, java.util.Iterator, org.apache.hadoop.mapred.OutputCollector, org.apache.hadoop.mapred.Reporter)">
  1067. reduce(WritableComparable, Iterator, OutputCollector, Reporter)</a>
  1068. method for each <span class="codefrag">&lt;key, (list of values)&gt;</span>
  1069. pair in the grouped inputs. Applications can then override the
  1070. <a href="api/org/apache/hadoop/io/Closeable.html#close()">
  1071. Closeable.close()</a> method to perform any required cleanup.</p>
  1072. <p>
  1073. <span class="codefrag">Reducer</span> has 3 primary phases: shuffle, sort and reduce.
  1074. </p>
  1075. <a name="N106B3"></a><a name="Shuffle"></a>
  1076. <h5>Shuffle</h5>
  1077. <p>Input to the <span class="codefrag">Reducer</span> is the sorted output of the
  1078. mappers. In this phase the framework fetches the relevant partition
  1079. of the output of all the mappers, via HTTP.</p>
  1080. <a name="N106C0"></a><a name="Sort"></a>
  1081. <h5>Sort</h5>
  1082. <p>The framework groups <span class="codefrag">Reducer</span> inputs by keys (since
  1083. different mappers may have output the same key) in this stage.</p>
  1084. <p>The shuffle and sort phases occur simultaneously; while
  1085. map-outputs are being fetched they are merged.</p>
  1086. <a name="N106CF"></a><a name="Secondary+Sort"></a>
  1087. <h5>Secondary Sort</h5>
  1088. <p>If equivalence rules for grouping the intermediate keys are
  1089. required to be different from those for grouping keys before
  1090. reduction, then one may specify a <span class="codefrag">Comparator</span> via
  1091. <a href="api/org/apache/hadoop/mapred/JobConf.html#setOutputValueGroupingComparator(java.lang.Class)">
  1092. JobConf.setOutputValueGroupingComparator(Class)</a>. Since
  1093. <a href="api/org/apache/hadoop/mapred/JobConf.html#setOutputKeyComparatorClass(java.lang.Class)">
  1094. JobConf.setOutputKeyComparatorClass(Class)</a> can be used to
  1095. control how intermediate keys are grouped, these can be used in
  1096. conjunction to simulate <em>secondary sort on values</em>.</p>
  1097. <a name="N106E8"></a><a name="Reduce"></a>
  1098. <h5>Reduce</h5>
  1099. <p>In this phase the
  1100. <a href="api/org/apache/hadoop/mapred/Reducer.html#reduce(K2, java.util.Iterator, org.apache.hadoop.mapred.OutputCollector, org.apache.hadoop.mapred.Reporter)">
  1101. reduce(WritableComparable, Iterator, OutputCollector, Reporter)</a>
  1102. method is called for each <span class="codefrag">&lt;key, (list of values)&gt;</span>
  1103. pair in the grouped inputs.</p>
  1104. <p>The output of the reduce task is typically written to the
  1105. <a href="api/org/apache/hadoop/fs/FileSystem.html">
  1106. FileSystem</a> via
  1107. <a href="api/org/apache/hadoop/mapred/OutputCollector.html#collect(K, V)">
  1108. OutputCollector.collect(WritableComparable, Writable)</a>.</p>
  1109. <p>Applications can use the <span class="codefrag">Reporter</span> to report
  1110. progress, set application-level status messages and update
  1111. <span class="codefrag">Counters</span>, or just indicate that they are alive.</p>
  1112. <p>The output of the <span class="codefrag">Reducer</span> is <em>not sorted</em>.</p>
  1113. <a name="N10716"></a><a name="How+Many+Reduces%3F"></a>
  1114. <h5>How Many Reduces?</h5>
  1115. <p>The right number of reduces seems to be <span class="codefrag">0.95</span> or
  1116. <span class="codefrag">1.75</span> multiplied by (&lt;<em>no. of nodes</em>&gt; *
  1117. <span class="codefrag">mapred.tasktracker.reduce.tasks.maximum</span>).</p>
  1118. <p>With <span class="codefrag">0.95</span> all of the reduces can launch immediately
  1119. and start transfering map outputs as the maps finish. With
  1120. <span class="codefrag">1.75</span> the faster nodes will finish their first round of
  1121. reduces and launch a second wave of reduces doing a much better job
  1122. of load balancing.</p>
  1123. <p>Increasing the number of reduces increases the framework overhead,
  1124. but increases load balancing and lowers the cost of failures.</p>
  1125. <p>The scaling factors above are slightly less than whole numbers to
  1126. reserve a few reduce slots in the framework for speculative-tasks and
  1127. failed tasks.</p>
  1128. <a name="N1073B"></a><a name="Reducer+NONE"></a>
  1129. <h5>Reducer NONE</h5>
  1130. <p>It is legal to set the number of reduce-tasks to <em>zero</em> if
  1131. no reduction is desired.</p>
  1132. <p>In this case the outputs of the map-tasks go directly to the
  1133. <span class="codefrag">FileSystem</span>, into the output path set by
  1134. <a href="api/org/apache/hadoop/mapred/FileInputFormat.html#setOutputPath(org.apache.hadoop.mapred.JobConf,%20org.apache.hadoop.fs.Path)">
  1135. setOutputPath(Path)</a>. The framework does not sort the
  1136. map-outputs before writing them out to the <span class="codefrag">FileSystem</span>.
  1137. </p>
  1138. <a name="N10756"></a><a name="Partitioner"></a>
  1139. <h4>Partitioner</h4>
  1140. <p>
  1141. <a href="api/org/apache/hadoop/mapred/Partitioner.html">
  1142. Partitioner</a> partitions the key space.</p>
  1143. <p>Partitioner controls the partitioning of the keys of the
  1144. intermediate map-outputs. The key (or a subset of the key) is used to
  1145. derive the partition, typically by a <em>hash function</em>. The total
  1146. number of partitions is the same as the number of reduce tasks for the
  1147. job. Hence this controls which of the <span class="codefrag">m</span> reduce tasks the
  1148. intermediate key (and hence the record) is sent to for reduction.</p>
  1149. <p>
  1150. <a href="api/org/apache/hadoop/mapred/lib/HashPartitioner.html">
  1151. HashPartitioner</a> is the default <span class="codefrag">Partitioner</span>.</p>
  1152. <a name="N10775"></a><a name="Reporter"></a>
  1153. <h4>Reporter</h4>
  1154. <p>
  1155. <a href="api/org/apache/hadoop/mapred/Reporter.html">
  1156. Reporter</a> is a facility for Map-Reduce applications to report
  1157. progress, set application-level status messages and update
  1158. <span class="codefrag">Counters</span>.</p>
  1159. <p>
  1160. <span class="codefrag">Mapper</span> and <span class="codefrag">Reducer</span> implementations can use
  1161. the <span class="codefrag">Reporter</span> to report progress or just indicate
  1162. that they are alive. In scenarios where the application takes a
  1163. significant amount of time to process individual key/value pairs,
  1164. this is crucial since the framework might assume that the task has
  1165. timed-out and kill that task. Another way to avoid this is to
  1166. set the configuration parameter <span class="codefrag">mapred.task.timeout</span> to a
  1167. high-enough value (or even set it to <em>zero</em> for no time-outs).
  1168. </p>
  1169. <p>Applications can also update <span class="codefrag">Counters</span> using the
  1170. <span class="codefrag">Reporter</span>.</p>
  1171. <a name="N1079F"></a><a name="OutputCollector"></a>
  1172. <h4>OutputCollector</h4>
  1173. <p>
  1174. <a href="api/org/apache/hadoop/mapred/OutputCollector.html">
  1175. OutputCollector</a> is a generalization of the facility provided by
  1176. the Map-Reduce framework to collect data output by the
  1177. <span class="codefrag">Mapper</span> or the <span class="codefrag">Reducer</span> (either the
  1178. intermediate outputs or the output of the job).</p>
  1179. <p>Hadoop Map-Reduce comes bundled with a
  1180. <a href="api/org/apache/hadoop/mapred/lib/package-summary.html">
  1181. library</a> of generally useful mappers, reducers, and partitioners.</p>
  1182. <a name="N107BA"></a><a name="Job+Configuration"></a>
  1183. <h3 class="h4">Job Configuration</h3>
  1184. <p>
  1185. <a href="api/org/apache/hadoop/mapred/JobConf.html">
  1186. JobConf</a> represents a Map-Reduce job configuration.</p>
  1187. <p>
  1188. <span class="codefrag">JobConf</span> is the primary interface for a user to describe
  1189. a map-reduce job to the Hadoop framework for execution. The framework
  1190. tries to faithfully execute the job as described by <span class="codefrag">JobConf</span>,
  1191. however:</p>
  1192. <ul>
  1193. <li>f
  1194. Some configuration parameters may have been marked as
  1195. <a href="api/org/apache/hadoop/conf/Configuration.html#FinalParams">
  1196. final</a> by administrators and hence cannot be altered.
  1197. </li>
  1198. <li>
  1199. While some job parameters are straight-forward to set (e.g.
  1200. <a href="api/org/apache/hadoop/mapred/JobConf.html#setNumReduceTasks(int)">
  1201. setNumReduceTasks(int)</a>), other parameters interact subtly with
  1202. the rest of the framework and/or job configuration and are
  1203. more complex to set (e.g.
  1204. <a href="api/org/apache/hadoop/mapred/JobConf.html#setNumMapTasks(int)">
  1205. setNumMapTasks(int)</a>).
  1206. </li>
  1207. </ul>
  1208. <p>
  1209. <span class="codefrag">JobConf</span> is typically used to specify the
  1210. <span class="codefrag">Mapper</span>, combiner (if any), <span class="codefrag">Partitioner</span>,
  1211. <span class="codefrag">Reducer</span>, <span class="codefrag">InputFormat</span> and
  1212. <span class="codefrag">OutputFormat</span> implementations. <span class="codefrag">JobConf</span> also
  1213. indicates the set of input files
  1214. (<a href="api/org/apache/hadoop/mapred/JobConf.html#setInputPath(org.apache.hadoop.fs.Path)">setInputPath(Path)</a>/<a href="api/org/apache/hadoop/mapred/JobConf.html#addInputPath(org.apache.hadoop.fs.Path)">addInputPath(Path)</a>)
  1215. and where the output files should be written
  1216. (<a href="api/org/apache/hadoop/mapred/FileInputFormat.html#setOutputPath(org.apache.hadoop.mapred.JobConf,%20org.apache.hadoop.fs.Path)">setOutputPath(Path)</a>).</p>
  1217. <p>Optionally, <span class="codefrag">JobConf</span> is used to specify other advanced
  1218. facets of the job such as the <span class="codefrag">Comparator</span> to be used, files
  1219. to be put in the <span class="codefrag">DistributedCache</span>, whether intermediate
  1220. and/or job outputs are to be compressed (and how), debugging via
  1221. user-provided scripts
  1222. (<a href="api/org/apache/hadoop/mapred/JobConf.html#setMapDebugScript(java.lang.String)">setMapDebugScript(String)</a>/<a href="api/org/apache/hadoop/mapred/JobConf.html#setReduceDebugScript(java.lang.String)">setReduceDebugScript(String)</a>)
  1223. , whether job tasks can be executed in a <em>speculative</em> manner
  1224. (<a href="api/org/apache/hadoop/mapred/JobConf.html#setMapSpeculativeExecution(boolean)">setMapSpeculativeExecution(boolean)</a>)/(<a href="api/org/apache/hadoop/mapred/JobConf.html#setReduceSpeculativeExecution(boolean)">setReduceSpeculativeExecution(boolean)</a>)
  1225. , maximum number of attempts per task
  1226. (<a href="api/org/apache/hadoop/mapred/JobConf.html#setMaxMapAttempts(int)">setMaxMapAttempts(int)</a>/<a href="api/org/apache/hadoop/mapred/JobConf.html#setMaxReduceAttempts(int)">setMaxReduceAttempts(int)</a>)
  1227. , percentage of tasks failure which can be tolerated by the job
  1228. (<a href="api/org/apache/hadoop/mapred/JobConf.html#setMaxMapTaskFailuresPercent(int)">setMaxMapTaskFailuresPercent(int)</a>/<a href="api/org/apache/hadoop/mapred/JobConf.html#setMaxReduceTaskFailuresPercent(int)">setMaxReduceTaskFailuresPercent(int)</a>)
  1229. etc.</p>
  1230. <p>Of course, users can use
  1231. <a href="api/org/apache/hadoop/conf/Configuration.html#set(java.lang.String, java.lang.String)">set(String, String)</a>/<a href="api/org/apache/hadoop/conf/Configuration.html#get(java.lang.String, java.lang.String)">get(String, String)</a>
  1232. to set/get arbitrary parameters needed by applications. However, use the
  1233. <span class="codefrag">DistributedCache</span> for large amounts of (read-only) data.</p>
  1234. <a name="N10844"></a><a name="Task+Execution+%26+Environment"></a>
  1235. <h3 class="h4">Task Execution &amp; Environment</h3>
  1236. <p>The <span class="codefrag">TaskTracker</span> executes the <span class="codefrag">Mapper</span>/
  1237. <span class="codefrag">Reducer</span> <em>task</em> as a child process in a separate jvm.
  1238. </p>
  1239. <p>The child-task inherits the environment of the parent
  1240. <span class="codefrag">TaskTracker</span>. The user can specify additional options to the
  1241. child-jvm via the <span class="codefrag">mapred.child.java.opts</span> configuration
  1242. parameter in the <span class="codefrag">JobConf</span> such as non-standard paths for the
  1243. run-time linker to search shared libraries via
  1244. <span class="codefrag">-Djava.library.path=&lt;&gt;</span> etc. If the
  1245. <span class="codefrag">mapred.child.java.opts</span> contains the symbol <em>@taskid@</em>
  1246. it is interpolated with value of <span class="codefrag">taskid</span> of the map/reduce
  1247. task.</p>
  1248. <p>Here is an example with multiple arguments and substitutions,
  1249. showing jvm GC logging, and start of a passwordless JVM JMX agent so that
  1250. it can connect with jconsole and the likes to watch child memory,
  1251. threads and get thread dumps. It also sets the maximum heap-size of the
  1252. child jvm to 512MB and adds an additional path to the
  1253. <span class="codefrag">java.library.path</span> of the child-jvm.</p>
  1254. <p>
  1255. <span class="codefrag">&lt;property&gt;</span>
  1256. <br>
  1257. &nbsp;&nbsp;<span class="codefrag">&lt;name&gt;mapred.child.java.opts&lt;/name&gt;</span>
  1258. <br>
  1259. &nbsp;&nbsp;<span class="codefrag">&lt;value&gt;</span>
  1260. <br>
  1261. &nbsp;&nbsp;&nbsp;&nbsp;<span class="codefrag">
  1262. -Xmx512M -Djava.library.path=/home/mycompany/lib
  1263. -verbose:gc -Xloggc:/tmp/@taskid@.gc</span>
  1264. <br>
  1265. &nbsp;&nbsp;&nbsp;&nbsp;<span class="codefrag">
  1266. -Dcom.sun.management.jmxremote.authenticate=false
  1267. -Dcom.sun.management.jmxremote.ssl=false</span>
  1268. <br>
  1269. &nbsp;&nbsp;<span class="codefrag">&lt;/value&gt;</span>
  1270. <br>
  1271. <span class="codefrag">&lt;/property&gt;</span>
  1272. </p>
  1273. <p>When the job starts, the localized job directory
  1274. <span class="codefrag"> ${mapred.local.dir}/taskTracker/jobcache/$jobid/</span>
  1275. has the following directories: </p>
  1276. <ul>
  1277. <li> A job-specific shared directory, created at location
  1278. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/work/ </span>.
  1279. This directory is exposed to the users through
  1280. <span class="codefrag">job.local.dir </span>. The tasks can use this space as scratch
  1281. space and share files among them. The directory can accessed through
  1282. api <a href="api/org/apache/hadoop/mapred/JobConf.html#getJobLocalDir()">
  1283. JobConf.getJobLocalDir()</a>. It is available as System property also.
  1284. So,users can call <span class="codefrag">System.getProperty("job.local.dir")</span>;
  1285. </li>
  1286. <li>A jars directory, which has the job jar file and expanded jar </li>
  1287. <li>A job.xml file, the generic job configuration </li>
  1288. <li>Each task has directory <span class="codefrag">task-id</span> which again has the
  1289. following structure
  1290. <ul>
  1291. <li>A job.xml file, task localized job configuration </li>
  1292. <li>A directory for intermediate output files</li>
  1293. <li>The working directory of the task.
  1294. And work directory has a temporary directory
  1295. to create temporary files</li>
  1296. </ul>
  1297. </li>
  1298. </ul>
  1299. <p>The <a href="#DistributedCache">DistributedCache</a> can also be used
  1300. as a rudimentary software distribution mechanism for use in the map
  1301. and/or reduce tasks. It can be used to distribute both jars and
  1302. native libraries. The
  1303. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#addArchiveToClassPath(org.apache.hadoop.fs.Path,%20org.apache.hadoop.conf.Configuration)">
  1304. DistributedCache.addArchiveToClassPath(Path, Configuration)</a> or
  1305. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#addFileToClassPath(org.apache.hadoop.fs.Path,%20org.apache.hadoop.conf.Configuration)">
  1306. DistributedCache.addFileToClassPath(Path, Configuration)</a> api can
  1307. be used to cache files/jars and also add them to the <em>classpath</em>
  1308. of child-jvm. Similarly the facility provided by the
  1309. <span class="codefrag">DistributedCache</span> where-in it symlinks the cached files into
  1310. the working directory of the task can be used to distribute native
  1311. libraries and load them. The underlying detail is that child-jvm always
  1312. has its <em>current working directory</em> added to the
  1313. <span class="codefrag">java.library.path</span> and hence the cached libraries can be
  1314. loaded via <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#loadLibrary(java.lang.String)">
  1315. System.loadLibrary</a> or <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#load(java.lang.String)">
  1316. System.load</a>.</p>
  1317. <a name="N108EA"></a><a name="Job+Submission+and+Monitoring"></a>
  1318. <h3 class="h4">Job Submission and Monitoring</h3>
  1319. <p>
  1320. <a href="api/org/apache/hadoop/mapred/JobClient.html">
  1321. JobClient</a> is the primary interface by which user-job interacts
  1322. with the <span class="codefrag">JobTracker</span>.</p>
  1323. <p>
  1324. <span class="codefrag">JobClient</span> provides facilities to submit jobs, track their
  1325. progress, access component-tasks' reports/logs, get the Map-Reduce
  1326. cluster's status information and so on.</p>
  1327. <p>The job submission process involves:</p>
  1328. <ol>
  1329. <li>Checking the input and output specifications of the job.</li>
  1330. <li>Computing the <span class="codefrag">InputSplit</span> values for the job.</li>
  1331. <li>
  1332. Setting up the requisite accounting information for the
  1333. <span class="codefrag">DistributedCache</span> of the job, if necessary.
  1334. </li>
  1335. <li>
  1336. Copying the job's jar and configuration to the map-reduce system
  1337. directory on the <span class="codefrag">FileSystem</span>.
  1338. </li>
  1339. <li>
  1340. Submitting the job to the <span class="codefrag">JobTracker</span> and optionally
  1341. monitoring it's status.
  1342. </li>
  1343. </ol>
  1344. <p> Job history files are also logged to user specified directory
  1345. <span class="codefrag">hadoop.job.history.user.location</span>
  1346. which defaults to job output directory. The files are stored in
  1347. "_logs/history/" in the specified directory. Hence, by default they
  1348. will be in mapred.output.dir/_logs/history. User can stop
  1349. logging by giving the value <span class="codefrag">none</span> for
  1350. <span class="codefrag">hadoop.job.history.user.location</span>
  1351. </p>
  1352. <p> User can view the history logs summary in specified directory
  1353. using the following command <br>
  1354. <span class="codefrag">$ bin/hadoop job -history output-dir</span>
  1355. <br>
  1356. This command will print job details, failed and killed tip
  1357. details. <br>
  1358. More details about the job such as successful tasks and
  1359. task attempts made for each task can be viewed using the
  1360. following command <br>
  1361. <span class="codefrag">$ bin/hadoop job -history all output-dir</span>
  1362. <br>
  1363. </p>
  1364. <p> User can use
  1365. <a href="api/org/apache/hadoop/mapred/OutputLogFilter.html">OutputLogFilter</a>
  1366. to filter log files from the output directory listing. </p>
  1367. <p>Normally the user creates the application, describes various facets
  1368. of the job via <span class="codefrag">JobConf</span>, and then uses the
  1369. <span class="codefrag">JobClient</span> to submit the job and monitor its progress.</p>
  1370. <a name="N1094A"></a><a name="Job+Control"></a>
  1371. <h4>Job Control</h4>
  1372. <p>Users may need to chain map-reduce jobs to accomplish complex
  1373. tasks which cannot be done via a single map-reduce job. This is fairly
  1374. easy since the output of the job typically goes to distributed
  1375. file-system, and the output, in turn, can be used as the input for the
  1376. next job.</p>
  1377. <p>However, this also means that the onus on ensuring jobs are
  1378. complete (success/failure) lies squarely on the clients. In such
  1379. cases, the various job-control options are:</p>
  1380. <ul>
  1381. <li>
  1382. <a href="api/org/apache/hadoop/mapred/JobClient.html#runJob(org.apache.hadoop.mapred.JobConf)">
  1383. runJob(JobConf)</a> : Submits the job and returns only after the
  1384. job has completed.
  1385. </li>
  1386. <li>
  1387. <a href="api/org/apache/hadoop/mapred/JobClient.html#submitJob(org.apache.hadoop.mapred.JobConf)">
  1388. submitJob(JobConf)</a> : Only submits the job, then poll the
  1389. returned handle to the
  1390. <a href="api/org/apache/hadoop/mapred/RunningJob.html">
  1391. RunningJob</a> to query status and make scheduling decisions.
  1392. </li>
  1393. <li>
  1394. <a href="api/org/apache/hadoop/mapred/JobConf.html#setJobEndNotificationURI(java.lang.String)">
  1395. JobConf.setJobEndNotificationURI(String)</a> : Sets up a
  1396. notification upon job-completion, thus avoiding polling.
  1397. </li>
  1398. </ul>
  1399. <a name="N10974"></a><a name="Job+Input"></a>
  1400. <h3 class="h4">Job Input</h3>
  1401. <p>
  1402. <a href="api/org/apache/hadoop/mapred/InputFormat.html">
  1403. InputFormat</a> describes the input-specification for a Map-Reduce job.
  1404. </p>
  1405. <p>The Map-Reduce framework relies on the <span class="codefrag">InputFormat</span> of
  1406. the job to:</p>
  1407. <ol>
  1408. <li>Validate the input-specification of the job.</li>
  1409. <li>
  1410. Split-up the input file(s) into logical <span class="codefrag">InputSplit</span>
  1411. instances, each of which is then assigned to an individual
  1412. <span class="codefrag">Mapper</span>.
  1413. </li>
  1414. <li>
  1415. Provide the <span class="codefrag">RecordReader</span> implementation used to
  1416. glean input records from the logical <span class="codefrag">InputSplit</span> for
  1417. processing by the <span class="codefrag">Mapper</span>.
  1418. </li>
  1419. </ol>
  1420. <p>The default behavior of file-based <span class="codefrag">InputFormat</span>
  1421. implementations, typically sub-classes of
  1422. <a href="api/org/apache/hadoop/mapred/FileInputFormat.html">
  1423. FileInputFormat</a>, is to split the input into <em>logical</em>
  1424. <span class="codefrag">InputSplit</span> instances based on the total size, in bytes, of
  1425. the input files. However, the <span class="codefrag">FileSystem</span> blocksize of the
  1426. input files is treated as an upper bound for input splits. A lower bound
  1427. on the split size can be set via <span class="codefrag">mapred.min.split.size</span>.</p>
  1428. <p>Clearly, logical splits based on input-size is insufficient for many
  1429. applications since record boundaries must be respected. In such cases,
  1430. the application should implement a <span class="codefrag">RecordReader</span>, who is
  1431. responsible for respecting record-boundaries and presents a
  1432. record-oriented view of the logical <span class="codefrag">InputSplit</span> to the
  1433. individual task.</p>
  1434. <p>
  1435. <a href="api/org/apache/hadoop/mapred/TextInputFormat.html">
  1436. TextInputFormat</a> is the default <span class="codefrag">InputFormat</span>.</p>
  1437. <p>If <span class="codefrag">TextInputFormat</span> is the <span class="codefrag">InputFormat</span> for a
  1438. given job, the framework detects input-files with the <em>.gz</em> and
  1439. <em>.lzo</em> extensions and automatically decompresses them using the
  1440. appropriate <span class="codefrag">CompressionCodec</span>. However, it must be noted that
  1441. compressed files with the above extensions cannot be <em>split</em> and
  1442. each compressed file is processed in its entirety by a single mapper.</p>
  1443. <a name="N109DE"></a><a name="InputSplit"></a>
  1444. <h4>InputSplit</h4>
  1445. <p>
  1446. <a href="api/org/apache/hadoop/mapred/InputSplit.html">
  1447. InputSplit</a> represents the data to be processed by an individual
  1448. <span class="codefrag">Mapper</span>.</p>
  1449. <p>Typically <span class="codefrag">InputSplit</span> presents a byte-oriented view of
  1450. the input, and it is the responsibility of <span class="codefrag">RecordReader</span>
  1451. to process and present a record-oriented view.</p>
  1452. <p>
  1453. <a href="api/org/apache/hadoop/mapred/FileSplit.html">
  1454. FileSplit</a> is the default <span class="codefrag">InputSplit</span>. It sets
  1455. <span class="codefrag">map.input.file</span> to the path of the input file for the
  1456. logical split.</p>
  1457. <a name="N10A03"></a><a name="RecordReader"></a>
  1458. <h4>RecordReader</h4>
  1459. <p>
  1460. <a href="api/org/apache/hadoop/mapred/RecordReader.html">
  1461. RecordReader</a> reads <span class="codefrag">&lt;key, value&gt;</span> pairs from an
  1462. <span class="codefrag">InputSplit</span>.</p>
  1463. <p>Typically the <span class="codefrag">RecordReader</span> converts the byte-oriented
  1464. view of the input, provided by the <span class="codefrag">InputSplit</span>, and
  1465. presents a record-oriented to the <span class="codefrag">Mapper</span> implementations
  1466. for processing. <span class="codefrag">RecordReader</span> thus assumes the
  1467. responsibility of processing record boundaries and presents the tasks
  1468. with keys and values.</p>
  1469. <a name="N10A26"></a><a name="Job+Output"></a>
  1470. <h3 class="h4">Job Output</h3>
  1471. <p>
  1472. <a href="api/org/apache/hadoop/mapred/OutputFormat.html">
  1473. OutputFormat</a> describes the output-specification for a Map-Reduce
  1474. job.</p>
  1475. <p>The Map-Reduce framework relies on the <span class="codefrag">OutputFormat</span> of
  1476. the job to:</p>
  1477. <ol>
  1478. <li>
  1479. Validate the output-specification of the job; for example, check that
  1480. the output directory doesn't already exist.
  1481. </li>
  1482. <li>
  1483. Provide the <span class="codefrag">RecordWriter</span> implementation used to
  1484. write the output files of the job. Output files are stored in a
  1485. <span class="codefrag">FileSystem</span>.
  1486. </li>
  1487. </ol>
  1488. <p>
  1489. <span class="codefrag">TextOutputFormat</span> is the default
  1490. <span class="codefrag">OutputFormat</span>.</p>
  1491. <a name="N10A4F"></a><a name="Task+Side-Effect+Files"></a>
  1492. <h4>Task Side-Effect Files</h4>
  1493. <p>In some applications, component tasks need to create and/or write to
  1494. side-files, which differ from the actual job-output files.</p>
  1495. <p>In such cases there could be issues with two instances of the same
  1496. <span class="codefrag">Mapper</span> or <span class="codefrag">Reducer</span> running simultaneously (for
  1497. example, speculative tasks) trying to open and/or write to the same
  1498. file (path) on the <span class="codefrag">FileSystem</span>. Hence the
  1499. application-writer will have to pick unique names per task-attempt
  1500. (using the taskid, say <span class="codefrag">task_200709221812_0001_m_000000_0</span>),
  1501. not just per task.</p>
  1502. <p>To avoid these issues the Map-Reduce framework maintains a special
  1503. <span class="codefrag">${mapred.output.dir}/_temporary/_${taskid}</span> sub-directory
  1504. accessible via <span class="codefrag">${mapred.work.output.dir}</span>
  1505. for each task-attempt on the <span class="codefrag">FileSystem</span> where the output
  1506. of the task-attempt is stored. On successful completion of the
  1507. task-attempt, the files in the
  1508. <span class="codefrag">${mapred.output.dir}/_temporary/_${taskid}</span> (only)
  1509. are <em>promoted</em> to <span class="codefrag">${mapred.output.dir}</span>. Of course,
  1510. the framework discards the sub-directory of unsuccessful task-attempts.
  1511. This process is completely transparent to the application.</p>
  1512. <p>The application-writer can take advantage of this feature by
  1513. creating any side-files required in <span class="codefrag">${mapred.work.output.dir}</span>
  1514. during execution of a task via
  1515. <a href="api/org/apache/hadoop/mapred/FileInputFormat.html#getWorkOutputPath(org.apache.hadoop.mapred.JobConf)">
  1516. FileOutputFormat.getWorkOutputPath()</a>, and the framework will promote them
  1517. similarly for succesful task-attempts, thus eliminating the need to
  1518. pick unique paths per task-attempt.</p>
  1519. <p>Note: The value of <span class="codefrag">${mapred.work.output.dir}</span> during
  1520. execution of a particular task-attempt is actually
  1521. <span class="codefrag">${mapred.output.dir}/_temporary/_{$taskid}</span>, and this value is
  1522. set by the map-reduce framework. So, just create any side-files in the
  1523. path returned by
  1524. <a href="api/org/apache/hadoop/mapred/FileInputFormat.html#getWorkOutputPath(org.apache.hadoop.mapred.JobConf)">
  1525. FileOutputFormat.getWorkOutputPath() </a>from map/reduce
  1526. task to take advantage of this feature.</p>
  1527. <p>The entire discussion holds true for maps of jobs with
  1528. reducer=NONE (i.e. 0 reduces) since output of the map, in that case,
  1529. goes directly to HDFS.</p>
  1530. <a name="N10A97"></a><a name="RecordWriter"></a>
  1531. <h4>RecordWriter</h4>
  1532. <p>
  1533. <a href="api/org/apache/hadoop/mapred/RecordWriter.html">
  1534. RecordWriter</a> writes the output <span class="codefrag">&lt;key, value&gt;</span>
  1535. pairs to an output file.</p>
  1536. <p>RecordWriter implementations write the job outputs to the
  1537. <span class="codefrag">FileSystem</span>.</p>
  1538. <a name="N10AAE"></a><a name="Other+Useful+Features"></a>
  1539. <h3 class="h4">Other Useful Features</h3>
  1540. <a name="N10AB4"></a><a name="Counters"></a>
  1541. <h4>Counters</h4>
  1542. <p>
  1543. <span class="codefrag">Counters</span> represent global counters, defined either by
  1544. the Map-Reduce framework or applications. Each <span class="codefrag">Counter</span> can
  1545. be of any <span class="codefrag">Enum</span> type. Counters of a particular
  1546. <span class="codefrag">Enum</span> are bunched into groups of type
  1547. <span class="codefrag">Counters.Group</span>.</p>
  1548. <p>Applications can define arbitrary <span class="codefrag">Counters</span> (of type
  1549. <span class="codefrag">Enum</span>) and update them via
  1550. <a href="api/org/apache/hadoop/mapred/Reporter.html#incrCounter(java.lang.Enum, long)">
  1551. Reporter.incrCounter(Enum, long)</a> in the <span class="codefrag">map</span> and/or
  1552. <span class="codefrag">reduce</span> methods. These counters are then globally
  1553. aggregated by the framework.</p>
  1554. <a name="N10ADF"></a><a name="DistributedCache"></a>
  1555. <h4>DistributedCache</h4>
  1556. <p>
  1557. <a href="api/org/apache/hadoop/filecache/DistributedCache.html">
  1558. DistributedCache</a> distributes application-specific, large, read-only
  1559. files efficiently.</p>
  1560. <p>
  1561. <span class="codefrag">DistributedCache</span> is a facility provided by the
  1562. Map-Reduce framework to cache files (text, archives, jars and so on)
  1563. needed by applications.</p>
  1564. <p>Applications specify the files to be cached via urls (hdfs:// or
  1565. http://) in the <span class="codefrag">JobConf</span>. The <span class="codefrag">DistributedCache</span>
  1566. assumes that the files specified via hdfs:// urls are already present
  1567. on the <span class="codefrag">FileSystem</span>.</p>
  1568. <p>The framework will copy the necessary files to the slave node
  1569. before any tasks for the job are executed on that node. Its
  1570. efficiency stems from the fact that the files are only copied once
  1571. per job and the ability to cache archives which are un-archived on
  1572. the slaves.</p>
  1573. <p>
  1574. <span class="codefrag">DistributedCache</span> tracks the modification timestamps of
  1575. the cached files. Clearly the cache files should not be modified by
  1576. the application or externally while the job is executing.</p>
  1577. <p>
  1578. <span class="codefrag">DistributedCache</span> can be used to distribute simple,
  1579. read-only data/text files and more complex types such as archives and
  1580. jars. Archives (zip files) are <em>un-archived</em> at the slave nodes.
  1581. Optionally users can also direct the <span class="codefrag">DistributedCache</span> to
  1582. <em>symlink</em> the cached file(s) into the <span class="codefrag">current working
  1583. directory</span> of the task via the
  1584. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#createSymlink(org.apache.hadoop.conf.Configuration)">
  1585. DistributedCache.createSymlink(Configuration)</a> api. Files
  1586. have <em>execution permissions</em> set.</p>
  1587. <a name="N10B1D"></a><a name="Tool"></a>
  1588. <h4>Tool</h4>
  1589. <p>The <a href="api/org/apache/hadoop/util/Tool.html">Tool</a>
  1590. interface supports the handling of generic Hadoop command-line options.
  1591. </p>
  1592. <p>
  1593. <span class="codefrag">Tool</span> is the standard for any Map-Reduce tool or
  1594. application. The application should delegate the handling of
  1595. standard command-line options to
  1596. <a href="api/org/apache/hadoop/util/GenericOptionsParser.html">
  1597. GenericOptionsParser</a> via
  1598. <a href="api/org/apache/hadoop/util/ToolRunner.html#run(org.apache.hadoop.util.Tool, java.lang.String[])">
  1599. ToolRunner.run(Tool, String[])</a> and only handle its custom
  1600. arguments.</p>
  1601. <p>
  1602. The generic Hadoop command-line options are:<br>
  1603. <span class="codefrag">
  1604. -conf &lt;configuration file&gt;
  1605. </span>
  1606. <br>
  1607. <span class="codefrag">
  1608. -D &lt;property=value&gt;
  1609. </span>
  1610. <br>
  1611. <span class="codefrag">
  1612. -fs &lt;local|namenode:port&gt;
  1613. </span>
  1614. <br>
  1615. <span class="codefrag">
  1616. -jt &lt;local|jobtracker:port&gt;
  1617. </span>
  1618. </p>
  1619. <a name="N10B4F"></a><a name="IsolationRunner"></a>
  1620. <h4>IsolationRunner</h4>
  1621. <p>
  1622. <a href="api/org/apache/hadoop/mapred/IsolationRunner.html">
  1623. IsolationRunner</a> is a utility to help debug Map-Reduce programs.</p>
  1624. <p>To use the <span class="codefrag">IsolationRunner</span>, first set
  1625. <span class="codefrag">keep.failed.tasks.files</span> to <span class="codefrag">true</span>
  1626. (also see <span class="codefrag">keep.tasks.files.pattern</span>).</p>
  1627. <p>
  1628. Next, go to the node on which the failed task ran and go to the
  1629. <span class="codefrag">TaskTracker</span>'s local directory and run the
  1630. <span class="codefrag">IsolationRunner</span>:<br>
  1631. <span class="codefrag">$ cd &lt;local path&gt;/taskTracker/${taskid}/work</span>
  1632. <br>
  1633. <span class="codefrag">
  1634. $ bin/hadoop org.apache.hadoop.mapred.IsolationRunner ../job.xml
  1635. </span>
  1636. </p>
  1637. <p>
  1638. <span class="codefrag">IsolationRunner</span> will run the failed task in a single
  1639. jvm, which can be in the debugger, over precisely the same input.</p>
  1640. <a name="N10B82"></a><a name="Debugging"></a>
  1641. <h4>Debugging</h4>
  1642. <p>Map/Reduce framework provides a facility to run user-provided
  1643. scripts for debugging. When map/reduce task fails, user can run
  1644. script for doing post-processing on task logs i.e task's stdout,
  1645. stderr, syslog and jobconf. The stdout and stderr of the
  1646. user-provided debug script are printed on the diagnostics.
  1647. These outputs are also displayed on job UI on demand. </p>
  1648. <p> In the following sections we discuss how to submit debug script
  1649. along with the job. For submitting debug script, first it has to
  1650. distributed. Then the script has to supplied in Configuration. </p>
  1651. <a name="N10B8E"></a><a name="How+to+distribute+script+file%3A"></a>
  1652. <h5> How to distribute script file: </h5>
  1653. <p>
  1654. To distribute the debug script file, first copy the file to the dfs.
  1655. The file can be distributed by setting the property
  1656. "mapred.cache.files" with value "path"#"script-name".
  1657. If more than one file has to be distributed, the files can be added
  1658. as comma separated paths. This property can also be set by APIs
  1659. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#addCacheFile(java.net.URI,%20org.apache.hadoop.conf.Configuration)">
  1660. DistributedCache.addCacheFile(URI,conf) </a> and
  1661. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#setCacheFiles(java.net.URI[],%20org.apache.hadoop.conf.Configuration)">
  1662. DistributedCache.setCacheFiles(URIs,conf) </a> where URI is of
  1663. the form "hdfs://host:port/'absolutepath'#'script-name'".
  1664. For Streaming, the file can be added through
  1665. command line option -cacheFile.
  1666. </p>
  1667. <p>
  1668. The files has to be symlinked in the current working directory of
  1669. of the task. To create symlink for the file, the property
  1670. "mapred.create.symlink" is set to "yes". This can also be set by
  1671. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#createSymlink(org.apache.hadoop.conf.Configuration)">
  1672. DistributedCache.createSymLink(Configuration) </a> api.
  1673. </p>
  1674. <a name="N10BA7"></a><a name="How+to+submit+script%3A"></a>
  1675. <h5> How to submit script: </h5>
  1676. <p> A quick way to submit debug script is to set values for the
  1677. properties "mapred.map.task.debug.script" and
  1678. "mapred.reduce.task.debug.script" for debugging map task and reduce
  1679. task respectively. These properties can also be set by using APIs
  1680. <a href="api/org/apache/hadoop/mapred/JobConf.html#setMapDebugScript(java.lang.String)">
  1681. JobConf.setMapDebugScript(String) </a> and
  1682. <a href="api/org/apache/hadoop/mapred/JobConf.html#setReduceDebugScript(java.lang.String)">
  1683. JobConf.setReduceDebugScript(String) </a>. For streaming, debug
  1684. script can be submitted with command-line options -mapdebug,
  1685. -reducedebug for debugging mapper and reducer respectively.</p>
  1686. <p>The arguments of the script are task's stdout, stderr,
  1687. syslog and jobconf files. The debug command, run on the node where
  1688. the map/reduce failed, is: <br>
  1689. <span class="codefrag"> $script $stdout $stderr $syslog $jobconf </span>
  1690. </p>
  1691. <p> Pipes programs have the c++ program name as a fifth argument
  1692. for the command. Thus for the pipes programs the command is <br>
  1693. <span class="codefrag">$script $stdout $stderr $syslog $jobconf $program </span>
  1694. </p>
  1695. <a name="N10BC9"></a><a name="Default+Behavior%3A"></a>
  1696. <h5> Default Behavior: </h5>
  1697. <p> For pipes, a default script is run to process core dumps under
  1698. gdb, prints stack trace and gives info about running threads. </p>
  1699. <a name="N10BD4"></a><a name="JobControl"></a>
  1700. <h4>JobControl</h4>
  1701. <p>
  1702. <a href="api/org/apache/hadoop/mapred/jobcontrol/package-summary.html">
  1703. JobControl</a> is a utility which encapsulates a set of Map-Reduce jobs
  1704. and their dependencies.</p>
  1705. <a name="N10BE1"></a><a name="Data+Compression"></a>
  1706. <h4>Data Compression</h4>
  1707. <p>Hadoop Map-Reduce provides facilities for the application-writer to
  1708. specify compression for both intermediate map-outputs and the
  1709. job-outputs i.e. output of the reduces. It also comes bundled with
  1710. <a href="api/org/apache/hadoop/io/compress/CompressionCodec.html">
  1711. CompressionCodec</a> implementations for the
  1712. <a href="http://www.zlib.net/">zlib</a> and <a href="http://www.oberhumer.com/opensource/lzo/">lzo</a> compression
  1713. algorithms. The <a href="http://www.gzip.org/">gzip</a> file format is also
  1714. supported.</p>
  1715. <p>Hadoop also provides native implementations of the above compression
  1716. codecs for reasons of both performance (zlib) and non-availability of
  1717. Java libraries (lzo). More details on their usage and availability are
  1718. available <a href="native_libraries.html">here</a>.</p>
  1719. <a name="N10C01"></a><a name="Intermediate+Outputs"></a>
  1720. <h5>Intermediate Outputs</h5>
  1721. <p>Applications can control compression of intermediate map-outputs
  1722. via the
  1723. <a href="api/org/apache/hadoop/mapred/JobConf.html#setCompressMapOutput(boolean)">
  1724. JobConf.setCompressMapOutput(boolean)</a> api and the
  1725. <span class="codefrag">CompressionCodec</span> to be used via the
  1726. <a href="api/org/apache/hadoop/mapred/JobConf.html#setMapOutputCompressorClass(java.lang.Class)">
  1727. JobConf.setMapOutputCompressorClass(Class)</a> api. Since
  1728. the intermediate map-outputs are always stored in the
  1729. <a href="api/org/apache/hadoop/io/SequenceFile.html">SequenceFile</a>
  1730. format, the
  1731. <a href="api/org/apache/hadoop/io/SequenceFile.CompressionType.html">
  1732. SequenceFile.CompressionType</a> (i.e.
  1733. <a href="api/org/apache/hadoop/io/SequenceFile.CompressionType.html#RECORD">
  1734. RECORD</a> /
  1735. <a href="api/org/apache/hadoop/io/SequenceFile.CompressionType.html#BLOCK">
  1736. BLOCK</a> - defaults to <span class="codefrag">RECORD</span>) can be specified via the
  1737. <a href="api/org/apache/hadoop/mapred/JobConf.html#setMapOutputCompressionType(org.apache.hadoop.io.SequenceFile.CompressionType)">
  1738. JobConf.setMapOutputCompressionType(SequenceFile.CompressionType)</a>
  1739. api.</p>
  1740. <a name="N10C2D"></a><a name="Job+Outputs"></a>
  1741. <h5>Job Outputs</h5>
  1742. <p>Applications can control compression of job-outputs via the
  1743. <a href="api/org/apache/hadoop/mapred/OutputFormatBase.html#setCompressOutput(org.apache.hadoop.mapred.JobConf,%20boolean)">
  1744. OutputFormatBase.setCompressOutput(JobConf, boolean)</a> api and the
  1745. <span class="codefrag">CompressionCodec</span> to be used can be specified via the
  1746. <a href="api/org/apache/hadoop/mapred/OutputFormatBase.html#setOutputCompressorClass(org.apache.hadoop.mapred.JobConf,%20java.lang.Class)">
  1747. OutputFormatBase.setOutputCompressorClass(JobConf, Class)</a> api.</p>
  1748. <p>If the job outputs are to be stored in the
  1749. <a href="api/org/apache/hadoop/mapred/SequenceFileOutputFormat.html">
  1750. SequenceFileOutputFormat</a>, the required
  1751. <span class="codefrag">SequenceFile.CompressionType</span> (i.e. <span class="codefrag">RECORD</span> /
  1752. <span class="codefrag">BLOCK</span> - defaults to <span class="codefrag">RECORD</span>)can be specified
  1753. via the
  1754. <a href="api/org/apache/hadoop/mapred/SequenceFileOutputFormat.html#setOutputCompressionType(org.apache.hadoop.mapred.JobConf,%20org.apache.hadoop.io.SequenceFile.CompressionType)">
  1755. SequenceFileOutputFormat.setOutputCompressionType(JobConf,
  1756. SequenceFile.CompressionType)</a> api.</p>
  1757. </div>
  1758. <a name="N10C5C"></a><a name="Example%3A+WordCount+v2.0"></a>
  1759. <h2 class="h3">Example: WordCount v2.0</h2>
  1760. <div class="section">
  1761. <p>Here is a more complete <span class="codefrag">WordCount</span> which uses many of the
  1762. features provided by the Map-Reduce framework we discussed so far.</p>
  1763. <p>This needs the HDFS to be up and running, especially for the
  1764. <span class="codefrag">DistributedCache</span>-related features. Hence it only works with a
  1765. <a href="quickstart.html#SingleNodeSetup">pseudo-distributed</a> or
  1766. <a href="quickstart.html#Fully-Distributed+Operation">fully-distributed</a>
  1767. Hadoop installation.</p>
  1768. <a name="N10C76"></a><a name="Source+Code-N10C76"></a>
  1769. <h3 class="h4">Source Code</h3>
  1770. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  1771. <tr>
  1772. <th colspan="1" rowspan="1"></th>
  1773. <th colspan="1" rowspan="1">WordCount.java</th>
  1774. </tr>
  1775. <tr>
  1776. <td colspan="1" rowspan="1">1.</td>
  1777. <td colspan="1" rowspan="1">
  1778. <span class="codefrag">package org.myorg;</span>
  1779. </td>
  1780. </tr>
  1781. <tr>
  1782. <td colspan="1" rowspan="1">2.</td>
  1783. <td colspan="1" rowspan="1"></td>
  1784. </tr>
  1785. <tr>
  1786. <td colspan="1" rowspan="1">3.</td>
  1787. <td colspan="1" rowspan="1">
  1788. <span class="codefrag">import java.io.*;</span>
  1789. </td>
  1790. </tr>
  1791. <tr>
  1792. <td colspan="1" rowspan="1">4.</td>
  1793. <td colspan="1" rowspan="1">
  1794. <span class="codefrag">import java.util.*;</span>
  1795. </td>
  1796. </tr>
  1797. <tr>
  1798. <td colspan="1" rowspan="1">5.</td>
  1799. <td colspan="1" rowspan="1"></td>
  1800. </tr>
  1801. <tr>
  1802. <td colspan="1" rowspan="1">6.</td>
  1803. <td colspan="1" rowspan="1">
  1804. <span class="codefrag">import org.apache.hadoop.fs.Path;</span>
  1805. </td>
  1806. </tr>
  1807. <tr>
  1808. <td colspan="1" rowspan="1">7.</td>
  1809. <td colspan="1" rowspan="1">
  1810. <span class="codefrag">import org.apache.hadoop.filecache.DistributedCache;</span>
  1811. </td>
  1812. </tr>
  1813. <tr>
  1814. <td colspan="1" rowspan="1">8.</td>
  1815. <td colspan="1" rowspan="1">
  1816. <span class="codefrag">import org.apache.hadoop.conf.*;</span>
  1817. </td>
  1818. </tr>
  1819. <tr>
  1820. <td colspan="1" rowspan="1">9.</td>
  1821. <td colspan="1" rowspan="1">
  1822. <span class="codefrag">import org.apache.hadoop.io.*;</span>
  1823. </td>
  1824. </tr>
  1825. <tr>
  1826. <td colspan="1" rowspan="1">10.</td>
  1827. <td colspan="1" rowspan="1">
  1828. <span class="codefrag">import org.apache.hadoop.mapred.*;</span>
  1829. </td>
  1830. </tr>
  1831. <tr>
  1832. <td colspan="1" rowspan="1">11.</td>
  1833. <td colspan="1" rowspan="1">
  1834. <span class="codefrag">import org.apache.hadoop.util.*;</span>
  1835. </td>
  1836. </tr>
  1837. <tr>
  1838. <td colspan="1" rowspan="1">12.</td>
  1839. <td colspan="1" rowspan="1"></td>
  1840. </tr>
  1841. <tr>
  1842. <td colspan="1" rowspan="1">13.</td>
  1843. <td colspan="1" rowspan="1">
  1844. <span class="codefrag">public class WordCount extends Configured implements Tool {</span>
  1845. </td>
  1846. </tr>
  1847. <tr>
  1848. <td colspan="1" rowspan="1">14.</td>
  1849. <td colspan="1" rowspan="1"></td>
  1850. </tr>
  1851. <tr>
  1852. <td colspan="1" rowspan="1">15.</td>
  1853. <td colspan="1" rowspan="1">
  1854. &nbsp;&nbsp;
  1855. <span class="codefrag">
  1856. public static class Map extends MapReduceBase
  1857. implements Mapper&lt;LongWritable, Text, Text, IntWritable&gt; {
  1858. </span>
  1859. </td>
  1860. </tr>
  1861. <tr>
  1862. <td colspan="1" rowspan="1">16.</td>
  1863. <td colspan="1" rowspan="1"></td>
  1864. </tr>
  1865. <tr>
  1866. <td colspan="1" rowspan="1">17.</td>
  1867. <td colspan="1" rowspan="1">
  1868. &nbsp;&nbsp;&nbsp;&nbsp;
  1869. <span class="codefrag">
  1870. static enum Counters { INPUT_WORDS }
  1871. </span>
  1872. </td>
  1873. </tr>
  1874. <tr>
  1875. <td colspan="1" rowspan="1">18.</td>
  1876. <td colspan="1" rowspan="1"></td>
  1877. </tr>
  1878. <tr>
  1879. <td colspan="1" rowspan="1">19.</td>
  1880. <td colspan="1" rowspan="1">
  1881. &nbsp;&nbsp;&nbsp;&nbsp;
  1882. <span class="codefrag">
  1883. private final static IntWritable one = new IntWritable(1);
  1884. </span>
  1885. </td>
  1886. </tr>
  1887. <tr>
  1888. <td colspan="1" rowspan="1">20.</td>
  1889. <td colspan="1" rowspan="1">
  1890. &nbsp;&nbsp;&nbsp;&nbsp;
  1891. <span class="codefrag">private Text word = new Text();</span>
  1892. </td>
  1893. </tr>
  1894. <tr>
  1895. <td colspan="1" rowspan="1">21.</td>
  1896. <td colspan="1" rowspan="1"></td>
  1897. </tr>
  1898. <tr>
  1899. <td colspan="1" rowspan="1">22.</td>
  1900. <td colspan="1" rowspan="1">
  1901. &nbsp;&nbsp;&nbsp;&nbsp;
  1902. <span class="codefrag">private boolean caseSensitive = true;</span>
  1903. </td>
  1904. </tr>
  1905. <tr>
  1906. <td colspan="1" rowspan="1">23.</td>
  1907. <td colspan="1" rowspan="1">
  1908. &nbsp;&nbsp;&nbsp;&nbsp;
  1909. <span class="codefrag">private Set&lt;String&gt; patternsToSkip = new HashSet&lt;String&gt;();</span>
  1910. </td>
  1911. </tr>
  1912. <tr>
  1913. <td colspan="1" rowspan="1">24.</td>
  1914. <td colspan="1" rowspan="1"></td>
  1915. </tr>
  1916. <tr>
  1917. <td colspan="1" rowspan="1">25.</td>
  1918. <td colspan="1" rowspan="1">
  1919. &nbsp;&nbsp;&nbsp;&nbsp;
  1920. <span class="codefrag">private long numRecords = 0;</span>
  1921. </td>
  1922. </tr>
  1923. <tr>
  1924. <td colspan="1" rowspan="1">26.</td>
  1925. <td colspan="1" rowspan="1">
  1926. &nbsp;&nbsp;&nbsp;&nbsp;
  1927. <span class="codefrag">private String inputFile;</span>
  1928. </td>
  1929. </tr>
  1930. <tr>
  1931. <td colspan="1" rowspan="1">27.</td>
  1932. <td colspan="1" rowspan="1"></td>
  1933. </tr>
  1934. <tr>
  1935. <td colspan="1" rowspan="1">28.</td>
  1936. <td colspan="1" rowspan="1">
  1937. &nbsp;&nbsp;&nbsp;&nbsp;
  1938. <span class="codefrag">public void configure(JobConf job) {</span>
  1939. </td>
  1940. </tr>
  1941. <tr>
  1942. <td colspan="1" rowspan="1">29.</td>
  1943. <td colspan="1" rowspan="1">
  1944. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1945. <span class="codefrag">
  1946. caseSensitive = job.getBoolean("wordcount.case.sensitive", true);
  1947. </span>
  1948. </td>
  1949. </tr>
  1950. <tr>
  1951. <td colspan="1" rowspan="1">30.</td>
  1952. <td colspan="1" rowspan="1">
  1953. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1954. <span class="codefrag">inputFile = job.get("map.input.file");</span>
  1955. </td>
  1956. </tr>
  1957. <tr>
  1958. <td colspan="1" rowspan="1">31.</td>
  1959. <td colspan="1" rowspan="1"></td>
  1960. </tr>
  1961. <tr>
  1962. <td colspan="1" rowspan="1">32.</td>
  1963. <td colspan="1" rowspan="1">
  1964. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1965. <span class="codefrag">if (job.getBoolean("wordcount.skip.patterns", false)) {</span>
  1966. </td>
  1967. </tr>
  1968. <tr>
  1969. <td colspan="1" rowspan="1">33.</td>
  1970. <td colspan="1" rowspan="1">
  1971. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1972. <span class="codefrag">Path[] patternsFiles = new Path[0];</span>
  1973. </td>
  1974. </tr>
  1975. <tr>
  1976. <td colspan="1" rowspan="1">34.</td>
  1977. <td colspan="1" rowspan="1">
  1978. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1979. <span class="codefrag">try {</span>
  1980. </td>
  1981. </tr>
  1982. <tr>
  1983. <td colspan="1" rowspan="1">35.</td>
  1984. <td colspan="1" rowspan="1">
  1985. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1986. <span class="codefrag">
  1987. patternsFiles = DistributedCache.getLocalCacheFiles(job);
  1988. </span>
  1989. </td>
  1990. </tr>
  1991. <tr>
  1992. <td colspan="1" rowspan="1">36.</td>
  1993. <td colspan="1" rowspan="1">
  1994. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1995. <span class="codefrag">} catch (IOException ioe) {</span>
  1996. </td>
  1997. </tr>
  1998. <tr>
  1999. <td colspan="1" rowspan="1">37.</td>
  2000. <td colspan="1" rowspan="1">
  2001. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2002. <span class="codefrag">
  2003. System.err.println("Caught exception while getting cached files: "
  2004. + StringUtils.stringifyException(ioe));
  2005. </span>
  2006. </td>
  2007. </tr>
  2008. <tr>
  2009. <td colspan="1" rowspan="1">38.</td>
  2010. <td colspan="1" rowspan="1">
  2011. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2012. <span class="codefrag">}</span>
  2013. </td>
  2014. </tr>
  2015. <tr>
  2016. <td colspan="1" rowspan="1">39.</td>
  2017. <td colspan="1" rowspan="1">
  2018. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2019. <span class="codefrag">for (Path patternsFile : patternsFiles) {</span>
  2020. </td>
  2021. </tr>
  2022. <tr>
  2023. <td colspan="1" rowspan="1">40.</td>
  2024. <td colspan="1" rowspan="1">
  2025. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2026. <span class="codefrag">parseSkipFile(patternsFile);</span>
  2027. </td>
  2028. </tr>
  2029. <tr>
  2030. <td colspan="1" rowspan="1">41.</td>
  2031. <td colspan="1" rowspan="1">
  2032. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2033. <span class="codefrag">}</span>
  2034. </td>
  2035. </tr>
  2036. <tr>
  2037. <td colspan="1" rowspan="1">42.</td>
  2038. <td colspan="1" rowspan="1">
  2039. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2040. <span class="codefrag">}</span>
  2041. </td>
  2042. </tr>
  2043. <tr>
  2044. <td colspan="1" rowspan="1">43.</td>
  2045. <td colspan="1" rowspan="1">
  2046. &nbsp;&nbsp;&nbsp;&nbsp;
  2047. <span class="codefrag">}</span>
  2048. </td>
  2049. </tr>
  2050. <tr>
  2051. <td colspan="1" rowspan="1">44.</td>
  2052. <td colspan="1" rowspan="1"></td>
  2053. </tr>
  2054. <tr>
  2055. <td colspan="1" rowspan="1">45.</td>
  2056. <td colspan="1" rowspan="1">
  2057. &nbsp;&nbsp;&nbsp;&nbsp;
  2058. <span class="codefrag">private void parseSkipFile(Path patternsFile) {</span>
  2059. </td>
  2060. </tr>
  2061. <tr>
  2062. <td colspan="1" rowspan="1">46.</td>
  2063. <td colspan="1" rowspan="1">
  2064. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2065. <span class="codefrag">try {</span>
  2066. </td>
  2067. </tr>
  2068. <tr>
  2069. <td colspan="1" rowspan="1">47.</td>
  2070. <td colspan="1" rowspan="1">
  2071. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2072. <span class="codefrag">
  2073. BufferedReader fis =
  2074. new BufferedReader(new FileReader(patternsFile.toString()));
  2075. </span>
  2076. </td>
  2077. </tr>
  2078. <tr>
  2079. <td colspan="1" rowspan="1">48.</td>
  2080. <td colspan="1" rowspan="1">
  2081. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2082. <span class="codefrag">String pattern = null;</span>
  2083. </td>
  2084. </tr>
  2085. <tr>
  2086. <td colspan="1" rowspan="1">49.</td>
  2087. <td colspan="1" rowspan="1">
  2088. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2089. <span class="codefrag">while ((pattern = fis.readLine()) != null) {</span>
  2090. </td>
  2091. </tr>
  2092. <tr>
  2093. <td colspan="1" rowspan="1">50.</td>
  2094. <td colspan="1" rowspan="1">
  2095. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2096. <span class="codefrag">patternsToSkip.add(pattern);</span>
  2097. </td>
  2098. </tr>
  2099. <tr>
  2100. <td colspan="1" rowspan="1">51.</td>
  2101. <td colspan="1" rowspan="1">
  2102. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2103. <span class="codefrag">}</span>
  2104. </td>
  2105. </tr>
  2106. <tr>
  2107. <td colspan="1" rowspan="1">52.</td>
  2108. <td colspan="1" rowspan="1">
  2109. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2110. <span class="codefrag">} catch (IOException ioe) {</span>
  2111. </td>
  2112. </tr>
  2113. <tr>
  2114. <td colspan="1" rowspan="1">53.</td>
  2115. <td colspan="1" rowspan="1">
  2116. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2117. <span class="codefrag">
  2118. System.err.println("Caught exception while parsing the cached file '" +
  2119. patternsFile + "' : " +
  2120. StringUtils.stringifyException(ioe));
  2121. </span>
  2122. </td>
  2123. </tr>
  2124. <tr>
  2125. <td colspan="1" rowspan="1">54.</td>
  2126. <td colspan="1" rowspan="1">
  2127. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2128. <span class="codefrag">}</span>
  2129. </td>
  2130. </tr>
  2131. <tr>
  2132. <td colspan="1" rowspan="1">55.</td>
  2133. <td colspan="1" rowspan="1">
  2134. &nbsp;&nbsp;&nbsp;&nbsp;
  2135. <span class="codefrag">}</span>
  2136. </td>
  2137. </tr>
  2138. <tr>
  2139. <td colspan="1" rowspan="1">56.</td>
  2140. <td colspan="1" rowspan="1"></td>
  2141. </tr>
  2142. <tr>
  2143. <td colspan="1" rowspan="1">57.</td>
  2144. <td colspan="1" rowspan="1">
  2145. &nbsp;&nbsp;&nbsp;&nbsp;
  2146. <span class="codefrag">
  2147. public void map(LongWritable key, Text value,
  2148. OutputCollector&lt;Text, IntWritable&gt; output,
  2149. Reporter reporter) throws IOException {
  2150. </span>
  2151. </td>
  2152. </tr>
  2153. <tr>
  2154. <td colspan="1" rowspan="1">58.</td>
  2155. <td colspan="1" rowspan="1">
  2156. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2157. <span class="codefrag">
  2158. String line =
  2159. (caseSensitive) ? value.toString() :
  2160. value.toString().toLowerCase();
  2161. </span>
  2162. </td>
  2163. </tr>
  2164. <tr>
  2165. <td colspan="1" rowspan="1">59.</td>
  2166. <td colspan="1" rowspan="1"></td>
  2167. </tr>
  2168. <tr>
  2169. <td colspan="1" rowspan="1">60.</td>
  2170. <td colspan="1" rowspan="1">
  2171. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2172. <span class="codefrag">for (String pattern : patternsToSkip) {</span>
  2173. </td>
  2174. </tr>
  2175. <tr>
  2176. <td colspan="1" rowspan="1">61.</td>
  2177. <td colspan="1" rowspan="1">
  2178. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2179. <span class="codefrag">line = line.replaceAll(pattern, "");</span>
  2180. </td>
  2181. </tr>
  2182. <tr>
  2183. <td colspan="1" rowspan="1">62.</td>
  2184. <td colspan="1" rowspan="1">
  2185. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2186. <span class="codefrag">}</span>
  2187. </td>
  2188. </tr>
  2189. <tr>
  2190. <td colspan="1" rowspan="1">63.</td>
  2191. <td colspan="1" rowspan="1"></td>
  2192. </tr>
  2193. <tr>
  2194. <td colspan="1" rowspan="1">64.</td>
  2195. <td colspan="1" rowspan="1">
  2196. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2197. <span class="codefrag">StringTokenizer tokenizer = new StringTokenizer(line);</span>
  2198. </td>
  2199. </tr>
  2200. <tr>
  2201. <td colspan="1" rowspan="1">65.</td>
  2202. <td colspan="1" rowspan="1">
  2203. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2204. <span class="codefrag">while (tokenizer.hasMoreTokens()) {</span>
  2205. </td>
  2206. </tr>
  2207. <tr>
  2208. <td colspan="1" rowspan="1">66.</td>
  2209. <td colspan="1" rowspan="1">
  2210. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2211. <span class="codefrag">word.set(tokenizer.nextToken());</span>
  2212. </td>
  2213. </tr>
  2214. <tr>
  2215. <td colspan="1" rowspan="1">67.</td>
  2216. <td colspan="1" rowspan="1">
  2217. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2218. <span class="codefrag">output.collect(word, one);</span>
  2219. </td>
  2220. </tr>
  2221. <tr>
  2222. <td colspan="1" rowspan="1">68.</td>
  2223. <td colspan="1" rowspan="1">
  2224. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2225. <span class="codefrag">reporter.incrCounter(Counters.INPUT_WORDS, 1);</span>
  2226. </td>
  2227. </tr>
  2228. <tr>
  2229. <td colspan="1" rowspan="1">69.</td>
  2230. <td colspan="1" rowspan="1">
  2231. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2232. <span class="codefrag">}</span>
  2233. </td>
  2234. </tr>
  2235. <tr>
  2236. <td colspan="1" rowspan="1">70.</td>
  2237. <td colspan="1" rowspan="1"></td>
  2238. </tr>
  2239. <tr>
  2240. <td colspan="1" rowspan="1">71.</td>
  2241. <td colspan="1" rowspan="1">
  2242. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2243. <span class="codefrag">if ((++numRecords % 100) == 0) {</span>
  2244. </td>
  2245. </tr>
  2246. <tr>
  2247. <td colspan="1" rowspan="1">72.</td>
  2248. <td colspan="1" rowspan="1">
  2249. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2250. <span class="codefrag">
  2251. reporter.setStatus("Finished processing " + numRecords +
  2252. " records " + "from the input file: " +
  2253. inputFile);
  2254. </span>
  2255. </td>
  2256. </tr>
  2257. <tr>
  2258. <td colspan="1" rowspan="1">73.</td>
  2259. <td colspan="1" rowspan="1">
  2260. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2261. <span class="codefrag">}</span>
  2262. </td>
  2263. </tr>
  2264. <tr>
  2265. <td colspan="1" rowspan="1">74.</td>
  2266. <td colspan="1" rowspan="1">
  2267. &nbsp;&nbsp;&nbsp;&nbsp;
  2268. <span class="codefrag">}</span>
  2269. </td>
  2270. </tr>
  2271. <tr>
  2272. <td colspan="1" rowspan="1">75.</td>
  2273. <td colspan="1" rowspan="1">
  2274. &nbsp;&nbsp;
  2275. <span class="codefrag">}</span>
  2276. </td>
  2277. </tr>
  2278. <tr>
  2279. <td colspan="1" rowspan="1">76.</td>
  2280. <td colspan="1" rowspan="1"></td>
  2281. </tr>
  2282. <tr>
  2283. <td colspan="1" rowspan="1">77.</td>
  2284. <td colspan="1" rowspan="1">
  2285. &nbsp;&nbsp;
  2286. <span class="codefrag">
  2287. public static class Reduce extends MapReduceBase implements
  2288. Reducer&lt;Text, IntWritable, Text, IntWritable&gt; {
  2289. </span>
  2290. </td>
  2291. </tr>
  2292. <tr>
  2293. <td colspan="1" rowspan="1">78.</td>
  2294. <td colspan="1" rowspan="1">
  2295. &nbsp;&nbsp;&nbsp;&nbsp;
  2296. <span class="codefrag">
  2297. public void reduce(Text key, Iterator&lt;IntWritable&gt; values,
  2298. OutputCollector&lt;Text, IntWritable&gt; output,
  2299. Reporter reporter) throws IOException {
  2300. </span>
  2301. </td>
  2302. </tr>
  2303. <tr>
  2304. <td colspan="1" rowspan="1">79.</td>
  2305. <td colspan="1" rowspan="1">
  2306. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2307. <span class="codefrag">int sum = 0;</span>
  2308. </td>
  2309. </tr>
  2310. <tr>
  2311. <td colspan="1" rowspan="1">80.</td>
  2312. <td colspan="1" rowspan="1">
  2313. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2314. <span class="codefrag">while (values.hasNext()) {</span>
  2315. </td>
  2316. </tr>
  2317. <tr>
  2318. <td colspan="1" rowspan="1">81.</td>
  2319. <td colspan="1" rowspan="1">
  2320. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2321. <span class="codefrag">sum += values.next().get();</span>
  2322. </td>
  2323. </tr>
  2324. <tr>
  2325. <td colspan="1" rowspan="1">82.</td>
  2326. <td colspan="1" rowspan="1">
  2327. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2328. <span class="codefrag">}</span>
  2329. </td>
  2330. </tr>
  2331. <tr>
  2332. <td colspan="1" rowspan="1">83.</td>
  2333. <td colspan="1" rowspan="1">
  2334. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2335. <span class="codefrag">output.collect(key, new IntWritable(sum));</span>
  2336. </td>
  2337. </tr>
  2338. <tr>
  2339. <td colspan="1" rowspan="1">84.</td>
  2340. <td colspan="1" rowspan="1">
  2341. &nbsp;&nbsp;&nbsp;&nbsp;
  2342. <span class="codefrag">}</span>
  2343. </td>
  2344. </tr>
  2345. <tr>
  2346. <td colspan="1" rowspan="1">85.</td>
  2347. <td colspan="1" rowspan="1">
  2348. &nbsp;&nbsp;
  2349. <span class="codefrag">}</span>
  2350. </td>
  2351. </tr>
  2352. <tr>
  2353. <td colspan="1" rowspan="1">86.</td>
  2354. <td colspan="1" rowspan="1"></td>
  2355. </tr>
  2356. <tr>
  2357. <td colspan="1" rowspan="1">87.</td>
  2358. <td colspan="1" rowspan="1">
  2359. &nbsp;&nbsp;
  2360. <span class="codefrag">public int run(String[] args) throws Exception {</span>
  2361. </td>
  2362. </tr>
  2363. <tr>
  2364. <td colspan="1" rowspan="1">88.</td>
  2365. <td colspan="1" rowspan="1">
  2366. &nbsp;&nbsp;&nbsp;&nbsp;
  2367. <span class="codefrag">
  2368. JobConf conf = new JobConf(getConf(), WordCount.class);
  2369. </span>
  2370. </td>
  2371. </tr>
  2372. <tr>
  2373. <td colspan="1" rowspan="1">89.</td>
  2374. <td colspan="1" rowspan="1">
  2375. &nbsp;&nbsp;&nbsp;&nbsp;
  2376. <span class="codefrag">conf.setJobName("wordcount");</span>
  2377. </td>
  2378. </tr>
  2379. <tr>
  2380. <td colspan="1" rowspan="1">90.</td>
  2381. <td colspan="1" rowspan="1"></td>
  2382. </tr>
  2383. <tr>
  2384. <td colspan="1" rowspan="1">91.</td>
  2385. <td colspan="1" rowspan="1">
  2386. &nbsp;&nbsp;&nbsp;&nbsp;
  2387. <span class="codefrag">conf.setOutputKeyClass(Text.class);</span>
  2388. </td>
  2389. </tr>
  2390. <tr>
  2391. <td colspan="1" rowspan="1">92.</td>
  2392. <td colspan="1" rowspan="1">
  2393. &nbsp;&nbsp;&nbsp;&nbsp;
  2394. <span class="codefrag">conf.setOutputValueClass(IntWritable.class);</span>
  2395. </td>
  2396. </tr>
  2397. <tr>
  2398. <td colspan="1" rowspan="1">93.</td>
  2399. <td colspan="1" rowspan="1"></td>
  2400. </tr>
  2401. <tr>
  2402. <td colspan="1" rowspan="1">94.</td>
  2403. <td colspan="1" rowspan="1">
  2404. &nbsp;&nbsp;&nbsp;&nbsp;
  2405. <span class="codefrag">conf.setMapperClass(Map.class);</span>
  2406. </td>
  2407. </tr>
  2408. <tr>
  2409. <td colspan="1" rowspan="1">95.</td>
  2410. <td colspan="1" rowspan="1">
  2411. &nbsp;&nbsp;&nbsp;&nbsp;
  2412. <span class="codefrag">conf.setCombinerClass(Reduce.class);</span>
  2413. </td>
  2414. </tr>
  2415. <tr>
  2416. <td colspan="1" rowspan="1">96.</td>
  2417. <td colspan="1" rowspan="1">
  2418. &nbsp;&nbsp;&nbsp;&nbsp;
  2419. <span class="codefrag">conf.setReducerClass(Reduce.class);</span>
  2420. </td>
  2421. </tr>
  2422. <tr>
  2423. <td colspan="1" rowspan="1">97.</td>
  2424. <td colspan="1" rowspan="1"></td>
  2425. </tr>
  2426. <tr>
  2427. <td colspan="1" rowspan="1">98.</td>
  2428. <td colspan="1" rowspan="1">
  2429. &nbsp;&nbsp;&nbsp;&nbsp;
  2430. <span class="codefrag">conf.setInputFormat(TextInputFormat.class);</span>
  2431. </td>
  2432. </tr>
  2433. <tr>
  2434. <td colspan="1" rowspan="1">99.</td>
  2435. <td colspan="1" rowspan="1">
  2436. &nbsp;&nbsp;&nbsp;&nbsp;
  2437. <span class="codefrag">conf.setOutputFormat(TextOutputFormat.class);</span>
  2438. </td>
  2439. </tr>
  2440. <tr>
  2441. <td colspan="1" rowspan="1">100.</td>
  2442. <td colspan="1" rowspan="1"></td>
  2443. </tr>
  2444. <tr>
  2445. <td colspan="1" rowspan="1">101.</td>
  2446. <td colspan="1" rowspan="1">
  2447. &nbsp;&nbsp;&nbsp;&nbsp;
  2448. <span class="codefrag">
  2449. List&lt;String&gt; other_args = new ArrayList&lt;String&gt;();
  2450. </span>
  2451. </td>
  2452. </tr>
  2453. <tr>
  2454. <td colspan="1" rowspan="1">102.</td>
  2455. <td colspan="1" rowspan="1">
  2456. &nbsp;&nbsp;&nbsp;&nbsp;
  2457. <span class="codefrag">for (int i=0; i &lt; args.length; ++i) {</span>
  2458. </td>
  2459. </tr>
  2460. <tr>
  2461. <td colspan="1" rowspan="1">103.</td>
  2462. <td colspan="1" rowspan="1">
  2463. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2464. <span class="codefrag">if ("-skip".equals(args[i])) {</span>
  2465. </td>
  2466. </tr>
  2467. <tr>
  2468. <td colspan="1" rowspan="1">104.</td>
  2469. <td colspan="1" rowspan="1">
  2470. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2471. <span class="codefrag">
  2472. DistributedCache.addCacheFile(new Path(args[++i]).toUri(), conf);
  2473. </span>
  2474. </td>
  2475. </tr>
  2476. <tr>
  2477. <td colspan="1" rowspan="1">105.</td>
  2478. <td colspan="1" rowspan="1">
  2479. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2480. <span class="codefrag">
  2481. conf.setBoolean("wordcount.skip.patterns", true);
  2482. </span>
  2483. </td>
  2484. </tr>
  2485. <tr>
  2486. <td colspan="1" rowspan="1">106.</td>
  2487. <td colspan="1" rowspan="1">
  2488. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2489. <span class="codefrag">} else {</span>
  2490. </td>
  2491. </tr>
  2492. <tr>
  2493. <td colspan="1" rowspan="1">107.</td>
  2494. <td colspan="1" rowspan="1">
  2495. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2496. <span class="codefrag">other_args.add(args[i]);</span>
  2497. </td>
  2498. </tr>
  2499. <tr>
  2500. <td colspan="1" rowspan="1">108.</td>
  2501. <td colspan="1" rowspan="1">
  2502. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2503. <span class="codefrag">}</span>
  2504. </td>
  2505. </tr>
  2506. <tr>
  2507. <td colspan="1" rowspan="1">109.</td>
  2508. <td colspan="1" rowspan="1">
  2509. &nbsp;&nbsp;&nbsp;&nbsp;
  2510. <span class="codefrag">}</span>
  2511. </td>
  2512. </tr>
  2513. <tr>
  2514. <td colspan="1" rowspan="1">110.</td>
  2515. <td colspan="1" rowspan="1"></td>
  2516. </tr>
  2517. <tr>
  2518. <td colspan="1" rowspan="1">111.</td>
  2519. <td colspan="1" rowspan="1">
  2520. &nbsp;&nbsp;&nbsp;&nbsp;
  2521. <span class="codefrag">conf.setInputPath(new Path(other_args.get(0)));</span>
  2522. </td>
  2523. </tr>
  2524. <tr>
  2525. <td colspan="1" rowspan="1">112.</td>
  2526. <td colspan="1" rowspan="1">
  2527. &nbsp;&nbsp;&nbsp;&nbsp;
  2528. <span class="codefrag">FileOutputFormat.setOutputPath(conf, new Path(other_args.get(1)));</span>
  2529. </td>
  2530. </tr>
  2531. <tr>
  2532. <td colspan="1" rowspan="1">113.</td>
  2533. <td colspan="1" rowspan="1"></td>
  2534. </tr>
  2535. <tr>
  2536. <td colspan="1" rowspan="1">114.</td>
  2537. <td colspan="1" rowspan="1">
  2538. &nbsp;&nbsp;&nbsp;&nbsp;
  2539. <span class="codefrag">JobClient.runJob(conf);</span>
  2540. </td>
  2541. </tr>
  2542. <tr>
  2543. <td colspan="1" rowspan="1">115.</td>
  2544. <td colspan="1" rowspan="1">
  2545. &nbsp;&nbsp;&nbsp;&nbsp;
  2546. <span class="codefrag">return 0;</span>
  2547. </td>
  2548. </tr>
  2549. <tr>
  2550. <td colspan="1" rowspan="1">116.</td>
  2551. <td colspan="1" rowspan="1">
  2552. &nbsp;&nbsp;
  2553. <span class="codefrag">}</span>
  2554. </td>
  2555. </tr>
  2556. <tr>
  2557. <td colspan="1" rowspan="1">117.</td>
  2558. <td colspan="1" rowspan="1"></td>
  2559. </tr>
  2560. <tr>
  2561. <td colspan="1" rowspan="1">118.</td>
  2562. <td colspan="1" rowspan="1">
  2563. &nbsp;&nbsp;
  2564. <span class="codefrag">
  2565. public static void main(String[] args) throws Exception {
  2566. </span>
  2567. </td>
  2568. </tr>
  2569. <tr>
  2570. <td colspan="1" rowspan="1">119.</td>
  2571. <td colspan="1" rowspan="1">
  2572. &nbsp;&nbsp;&nbsp;&nbsp;
  2573. <span class="codefrag">
  2574. int res = ToolRunner.run(new Configuration(), new WordCount(),
  2575. args);
  2576. </span>
  2577. </td>
  2578. </tr>
  2579. <tr>
  2580. <td colspan="1" rowspan="1">120.</td>
  2581. <td colspan="1" rowspan="1">
  2582. &nbsp;&nbsp;&nbsp;&nbsp;
  2583. <span class="codefrag">System.exit(res);</span>
  2584. </td>
  2585. </tr>
  2586. <tr>
  2587. <td colspan="1" rowspan="1">121.</td>
  2588. <td colspan="1" rowspan="1">
  2589. &nbsp;&nbsp;
  2590. <span class="codefrag">}</span>
  2591. </td>
  2592. </tr>
  2593. <tr>
  2594. <td colspan="1" rowspan="1">122.</td>
  2595. <td colspan="1" rowspan="1">
  2596. <span class="codefrag">}</span>
  2597. </td>
  2598. </tr>
  2599. <tr>
  2600. <td colspan="1" rowspan="1">123.</td>
  2601. <td colspan="1" rowspan="1"></td>
  2602. </tr>
  2603. </table>
  2604. <a name="N113D8"></a><a name="Sample+Runs"></a>
  2605. <h3 class="h4">Sample Runs</h3>
  2606. <p>Sample text-files as input:</p>
  2607. <p>
  2608. <span class="codefrag">$ bin/hadoop dfs -ls /usr/joe/wordcount/input/</span>
  2609. <br>
  2610. <span class="codefrag">/usr/joe/wordcount/input/file01</span>
  2611. <br>
  2612. <span class="codefrag">/usr/joe/wordcount/input/file02</span>
  2613. <br>
  2614. <br>
  2615. <span class="codefrag">$ bin/hadoop dfs -cat /usr/joe/wordcount/input/file01</span>
  2616. <br>
  2617. <span class="codefrag">Hello World, Bye World!</span>
  2618. <br>
  2619. <br>
  2620. <span class="codefrag">$ bin/hadoop dfs -cat /usr/joe/wordcount/input/file02</span>
  2621. <br>
  2622. <span class="codefrag">Hello Hadoop, Goodbye to hadoop.</span>
  2623. </p>
  2624. <p>Run the application:</p>
  2625. <p>
  2626. <span class="codefrag">
  2627. $ bin/hadoop jar /usr/joe/wordcount.jar org.myorg.WordCount
  2628. /usr/joe/wordcount/input /usr/joe/wordcount/output
  2629. </span>
  2630. </p>
  2631. <p>Output:</p>
  2632. <p>
  2633. <span class="codefrag">
  2634. $ bin/hadoop dfs -cat /usr/joe/wordcount/output/part-00000
  2635. </span>
  2636. <br>
  2637. <span class="codefrag">Bye 1</span>
  2638. <br>
  2639. <span class="codefrag">Goodbye 1</span>
  2640. <br>
  2641. <span class="codefrag">Hadoop, 1</span>
  2642. <br>
  2643. <span class="codefrag">Hello 2</span>
  2644. <br>
  2645. <span class="codefrag">World! 1</span>
  2646. <br>
  2647. <span class="codefrag">World, 1</span>
  2648. <br>
  2649. <span class="codefrag">hadoop. 1</span>
  2650. <br>
  2651. <span class="codefrag">to 1</span>
  2652. <br>
  2653. </p>
  2654. <p>Notice that the inputs differ from the first version we looked at,
  2655. and how they affect the outputs.</p>
  2656. <p>Now, lets plug-in a pattern-file which lists the word-patterns to be
  2657. ignored, via the <span class="codefrag">DistributedCache</span>.</p>
  2658. <p>
  2659. <span class="codefrag">$ hadoop dfs -cat /user/joe/wordcount/patterns.txt</span>
  2660. <br>
  2661. <span class="codefrag">\.</span>
  2662. <br>
  2663. <span class="codefrag">\,</span>
  2664. <br>
  2665. <span class="codefrag">\!</span>
  2666. <br>
  2667. <span class="codefrag">to</span>
  2668. <br>
  2669. </p>
  2670. <p>Run it again, this time with more options:</p>
  2671. <p>
  2672. <span class="codefrag">
  2673. $ bin/hadoop jar /usr/joe/wordcount.jar org.myorg.WordCount
  2674. -Dwordcount.case.sensitive=true /usr/joe/wordcount/input
  2675. /usr/joe/wordcount/output -skip /user/joe/wordcount/patterns.txt
  2676. </span>
  2677. </p>
  2678. <p>As expected, the output:</p>
  2679. <p>
  2680. <span class="codefrag">
  2681. $ bin/hadoop dfs -cat /usr/joe/wordcount/output/part-00000
  2682. </span>
  2683. <br>
  2684. <span class="codefrag">Bye 1</span>
  2685. <br>
  2686. <span class="codefrag">Goodbye 1</span>
  2687. <br>
  2688. <span class="codefrag">Hadoop 1</span>
  2689. <br>
  2690. <span class="codefrag">Hello 2</span>
  2691. <br>
  2692. <span class="codefrag">World 2</span>
  2693. <br>
  2694. <span class="codefrag">hadoop 1</span>
  2695. <br>
  2696. </p>
  2697. <p>Run it once more, this time switch-off case-sensitivity:</p>
  2698. <p>
  2699. <span class="codefrag">
  2700. $ bin/hadoop jar /usr/joe/wordcount.jar org.myorg.WordCount
  2701. -Dwordcount.case.sensitive=false /usr/joe/wordcount/input
  2702. /usr/joe/wordcount/output -skip /user/joe/wordcount/patterns.txt
  2703. </span>
  2704. </p>
  2705. <p>Sure enough, the output:</p>
  2706. <p>
  2707. <span class="codefrag">
  2708. $ bin/hadoop dfs -cat /usr/joe/wordcount/output/part-00000
  2709. </span>
  2710. <br>
  2711. <span class="codefrag">bye 1</span>
  2712. <br>
  2713. <span class="codefrag">goodbye 1</span>
  2714. <br>
  2715. <span class="codefrag">hadoop 2</span>
  2716. <br>
  2717. <span class="codefrag">hello 2</span>
  2718. <br>
  2719. <span class="codefrag">world 2</span>
  2720. <br>
  2721. </p>
  2722. <a name="N114AC"></a><a name="Highlights"></a>
  2723. <h3 class="h4">Highlights</h3>
  2724. <p>The second version of <span class="codefrag">WordCount</span> improves upon the
  2725. previous one by using some features offered by the Map-Reduce framework:
  2726. </p>
  2727. <ul>
  2728. <li>
  2729. Demonstrates how applications can access configuration parameters
  2730. in the <span class="codefrag">configure</span> method of the <span class="codefrag">Mapper</span> (and
  2731. <span class="codefrag">Reducer</span>) implementations (lines 28-43).
  2732. </li>
  2733. <li>
  2734. Demonstrates how the <span class="codefrag">DistributedCache</span> can be used to
  2735. distribute read-only data needed by the jobs. Here it allows the user
  2736. to specify word-patterns to skip while counting (line 104).
  2737. </li>
  2738. <li>
  2739. Demonstrates the utility of the <span class="codefrag">Tool</span> interface and the
  2740. <span class="codefrag">GenericOptionsParser</span> to handle generic Hadoop
  2741. command-line options (lines 87-116, 119).
  2742. </li>
  2743. <li>
  2744. Demonstrates how applications can use <span class="codefrag">Counters</span> (line 68)
  2745. and how they can set application-specific status information via
  2746. the <span class="codefrag">Reporter</span> instance passed to the <span class="codefrag">map</span> (and
  2747. <span class="codefrag">reduce</span>) method (line 72).
  2748. </li>
  2749. </ul>
  2750. </div>
  2751. <p>
  2752. <em>Java and JNI are trademarks or registered trademarks of
  2753. Sun Microsystems, Inc. in the United States and other countries.</em>
  2754. </p>
  2755. </div>
  2756. <!--+
  2757. |end content
  2758. +-->
  2759. <div class="clearboth">&nbsp;</div>
  2760. </div>
  2761. <div id="footer">
  2762. <!--+
  2763. |start bottomstrip
  2764. +-->
  2765. <div class="lastmodified">
  2766. <script type="text/javascript"><!--
  2767. document.write("Last Published: " + document.lastModified);
  2768. // --></script>
  2769. </div>
  2770. <div class="copyright">
  2771. Copyright &copy;
  2772. 2007 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
  2773. </div>
  2774. <!--+
  2775. |end bottomstrip
  2776. +-->
  2777. </div>
  2778. </body>
  2779. </html>