HBase中怎么把數(shù)據(jù)寫到HDFS文件中

這篇文章主要講解了“HBase中怎么把數(shù)據(jù)寫到HDFS文件中”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“HBase中怎么把數(shù)據(jù)寫到HDFS文件中”吧!

河南網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)公司2013年成立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)

從HBase中選定某張表,比如blog,然后限定表中的某些列,比如昵稱nickname,標(biāo)簽tags,將這些列的數(shù)據(jù)內(nèi)容寫入到HDFS文件中去。

/***選定HBase中的某張表,限定列,然后將其內(nèi)容數(shù)據(jù)寫入到HDFS文件中。**/publicclassHBaseAndMapReduce2{publicstaticvoidmain(String[]args)throwsException{System.exit(run());}publicstaticintrun()throwsException{Configurationconf=newConfiguration();conf=HBaseConfiguration.create(conf);conf.set("hbase.zookeeper.quorum","192.168.226.129");Jobjob=Job.getInstance(conf,"findFriend");job.setJarByClass(HBaseAndMapReduce2.class);Scanscan=newScan();//取對(duì)業(yè)務(wù)有用的數(shù)據(jù)tags,nicknamescan.addColumn(Bytes.toBytes("article"),Bytes.toBytes("tags"));scan.addColumn(Bytes.toBytes("author"),Bytes.toBytes("nickname"));//ImmutableBytesWritable來(lái)自hbase數(shù)據(jù)的類型/***publicstaticvoidinitTableMapperJob(Stringtable,Scanscan,*Class<?extendsTableMapper>mapper,*Class<?>outputKeyClass,*Class<?>outputValueClass,Jobjob)**///確保blog表存在,且表結(jié)構(gòu)與本文一樣。TableMapReduceUtil.initTableMapperJob("blog",scan,FindFriendMapper.class,Text.class,Text.class,job);DateFormatdf=newSimpleDateFormat("yyyyMMddHHmmssS");FileOutputFormat.setOutputPath(job,newPath("hdfs://192.168.226.129:9000/hbasemapreduce1/"+df.format(newDate())));job.setReducerClass(FindFriendReducer.class);returnjob.waitForCompletion(true)?0:1;}//輸入輸出的鍵值publicstaticclassFindFriendMapperextendsTableMapper<Text,Text>{//key是hbase中的行鍵//value是hbase中的所行鍵的所有數(shù)據(jù)@Overrideprotectedvoidmap(ImmutableBytesWritablekey,Resultvalue,Mapper<ImmutableBytesWritable,Result,Text,Text>.Contextcontext)throwsIOException,InterruptedException{Textv=null;String[]kStrs=null;List<Cell>cs=value.listCells();for(Cellcell:cs){System.out.println("Cell--->:"+cell);if("tags".equals(Bytes.toString(CellUtil.cloneQualifier(cell)))){kStrs=Bytes.toString(CellUtil.cloneValue(cell)).split(",");}elseif("nickname".equals(Bytes.toString(CellUtil.cloneQualifier(cell)))){v=newText(CellUtil.cloneValue(cell));}}for(StringkStr:kStrs){context.write(newText(kStr.toLowerCase()),v);}}}publicstaticclassFindFriendReducerextendsReducer<Text,Text,Text,Text>{@Overrideprotectedvoidreduce(Textkey,Iterable<Text>values,Reducer<Text,Text,Text,Text>.Contextcontext)throwsIOException,InterruptedException{System.out.println("key--->"+key);StringBuildersb=newStringBuilder();for(Texttext:values){System.out.println("value-->"+text);sb.append((sb.length()>0?",":"")+text.toString());}context.write(key,newText(sb.toString()));}}}

輸出結(jié)構(gòu):

hadoopBerg-OSChina,BergBerghbaseOSChina,BergBergzookeeperOSChina,BergBerg

感謝各位的閱讀,以上就是“HBase中怎么把數(shù)據(jù)寫到HDFS文件中”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)HBase中怎么把數(shù)據(jù)寫到HDFS文件中這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是箭頭云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

網(wǎng)站題目:HBase中怎么把數(shù)據(jù)寫到HDFS文件中
路徑分享:http://muchs.cn/article44/chsehe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版網(wǎng)站設(shè)計(jì)、響應(yīng)式網(wǎng)站外貿(mào)建站、虛擬主機(jī)、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)