十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
一:先寫map類
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、武川網(wǎng)絡(luò)推廣、微信平臺(tái)小程序開發(fā)、武川網(wǎng)絡(luò)營(yíng)銷、武川企業(yè)策劃、武川品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供武川建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:www.cdcxhl.com
import sys for line in sys.stdin: line = line.strip( ) words = line.split( ) for word in words: print('%s\t%s' % (word, 1))
二:寫reduce類
import sys current_word = None current_count = 0 word = None for line in sys.stdin: line = line.strip() word, count = line.split('\t',1) try: count = int(count) except ValueError: continue if current_word == word: current_count += count else: if current_word: print('%s\t%s' % (current_word,current_count)) current_count = count current_word = word if current_word == word: print('%s\t%s' % (current_word,current_count))
三:利用hadoop Streaming執(zhí)行Python的內(nèi)容。
hadoop jar /home/hadoop/hadoop-2.6.0-cdh6.5.2/share/hadoop/tools/lib/hadoop-streaming-2.6.0-cdh6.5.2.jar -input /user/hadoop/aa.txt -output /user/hadoop/python_output -mapper "python mapper.py" -reducer "python reducer.py" -file mapper.py-file reducer.py
說明:
輸入和輸出路徑,本身就是hdfs上的,不需要特殊指定hdfs。
不加×××部分的引號(hào)的話,會(huì)報(bào)錯(cuò)誤:
Error: java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 2
不加粉色部分的內(nèi)容的話,會(huì)報(bào)錯(cuò)誤:
Error: java.lang.RuntimeException: Error in configuring object