您好,登錄后才能下訂單哦!
1、描述spark中怎么加載lzo壓縮格式的文件
2、比較lzo格式文件以textFile方式和LzoTextInputFormat方式計算數據,Running Tasks個數的影響
a.確保lzo文件所在文件夾中生成lzo.index索引文件
(對該lzo壓縮文件進行index操作,生成lzo.index文件,map操作才可以進行split
hadoop jar ${HADOOP_HOME}/lib/hadoop-lzo.jar com.hadoop.compression.lzo.DistributedLzoIndexer /wh/source/)
b.以LzoTextInputFormat處理,能夠正常按分塊數分配Tasks
查看文件塊數量
[tech@dx2 ~]$ hdfs fsck /wh/source/hotel.2017-08-07.txt_10.10.10.10_20170807.lzo Connecting to namenode via http://nn1.zdp.ol:50070 FSCK started by bwtech (auth:SIMPLE) from /10.10.10.10 for path /wh/source/hotel.2017-08-07.txt_10.10.16.105_20170807.lzo at Tue Aug 08 15:27:52 CST 2017 .Status: HEALTHY Total size:2892666412 B Total dirs:0 Total files:1 Total symlinks:0 Total blocks (validated):11 (avg. block size 262969673 B) Minimally replicated blocks:11 (100.0 %) Over-replicated blocks:0 (0.0 %) Under-replicated blocks:0 (0.0 %) Mis-replicated blocks:0 (0.0 %) Default replication factor:3 Average block replication:3.0 Corrupt blocks:0 Missing replicas:0 (0.0 %) Number of data-nodes:21 Number of racks:2 FSCK ended at Tue Aug 08 15:27:52 CST 2017 in 3 milliseconds
Spark源代碼可以參考https://github.com/chocolateBlack/LearningSpark/blob/master/src/main/scala-2.11/SparkLzoFile.scala
import com.hadoop.mapreduce.LzoTextInputFormat import org.apache.hadoop.io.{Text, LongWritable} import org.apache.spark.{SparkContext, SparkConf} object SparkLzoFile{ def main(args:Array[String]){ val conf = new SparkConf().setAppName("Spark_Lzo_File") val sc = new SparkContext(conf) //文件路徑 val filePath = "/wh/source/hotel.2017-08-07.txt_10.10.10.10_20170807.lzo" //按textFile方式加載文件 val textFile = sc.textFile(filePath) //按lzoTextInputFormat加載數據文件 val lzoFile = sc.newAPIHadoopFile[LongWritable, Text, LzoTextInputFormat](filePath) println(textFile.partitions.length)// partitions個數輸出 1 println(lzoFile.partitions.length)// partitions個數輸出 11 //兩種方式計算word count查看后臺任務 lzoFile.map(_._2.toString).flatMap(x=>x.split("-")).map((_,1)).reduceByKey(_+_).collect textFile.flatMap(x=>x.split("\t")).map((_,1)).reduceByKey(_+_).collect } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。