【轉】MapReduce讀取lzo檔案

來源:互聯網
上載者:User

標籤:

1.讀lzo檔案

需要添加以下代碼,並匯入lzo相關的jar包
 job.setInputFormatClass(LzoTextInputFormat.class);


2.寫lzo檔案

lzo格式預設是不支援splitable的,需要為其添加索引檔案,才能支援多個map並行對lzo檔案進行處理


如果希望reduce輸出的是lzo格式的檔案,添加下面的語句
        FileOutputFormat.setCompressOutput(job, true);
        FileOutputFormat.setOutputCompressorClass(job, LzopCodec.class);
        int result = job.waitForCompletion(true) ? 0 : 1;
        //上面的語句執行完成後,會產生最後的輸出檔案,需要在此基礎上添加lzo的索引
        LzoIndexer lzoIndexer = new LzoIndexer(conf);
        lzoIndexer.index(new Path(args[1]));


如果已經存在lzo檔案,但沒有添加索引,可以採用下面的方法,在輸入路徑的檔案上上添加lzo索引

hadoop jar $HADOOP_HOME/lib/hadoop-lzo-0.4.17.jar com.hadoop.compression.lzo.LzoIndexer hdf://inputpath

或者 

hadoop jar $HADOOP_HOME/lib/hadoop-lzo-0.4.17.jar com.hadoop.compression.lzo.DistributedLzoIndexe hdf://inputpath

 

【轉自】http://blog.csdn.net/wisgood/article/details/17080361

【轉】MapReduce讀取lzo檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.