spark rdd是被分割槽的,在生成rdd時候,一般可以指定分割槽的數量,如果不指定分割槽數量,當rdd從集合建立時候,則預設為該程式所分配到的資源的cpu核數,如果是從hdfs檔案建立,預設為檔案的block數。
具體看例子:
//建立乙個rdd,預設分割槽15個,因為我的spark-shell指定了一共使用15個cpu資源
//–total-executor-cores 15
scala> var rdd1 = sc.makerdd(1 to 50)
rdd1: org.apache.spark.rdd.rdd[int] = parallelcollectionrdd[17] at makerdd at :21
scala> rdd1.partitions.size
res15: int = 15
//統計rdd1每個分割槽中元素數量
(partidx,iter) => else
iter.next()
}part_map.iterator
}}.collect
res16: array[(string, int)] = array((part_0,3), (part_1,3), (part_2,4), (part_3,3),
(part_4,3), (part_5,4), (part_6,3), (part_7,3), (part_8,4), (part_9,3), (part_10,3),
(part_11,4), (part_12,3), (part_13,3), (part_14,4))
//從part_0到part_14,每個分割槽中的元素數量
//統計rdd1每個分割槽中有哪些元素
(partidx,iter) => else }}
part_map.iterator
}}.collect
res17: array[(string, list[int])] = array((part_0,list(3, 2, 1)), (part_1,list(6, 5, 4)),
(part_2,list(10, 9, 8, 7)), (part_3,list(13, 12, 11)), (part_4,list(16, 15, 14)),
(part_5,list(20, 19, 18, 17)), (part_6,list(23, 22, 21)), (part_7,list(26, 25, 24)),
(part_8,list(30, 29, 28, 27)), (part_9,list(33, 32, 31)), (part_10,list(36, 35, 34)),
(part_11,list(40, 39, 38, 37)), (part_12,list(43, 42, 41)), (part_13,list(46, 45, 44)),
(part_14,list(50, 49, 48, 47)))
//從part_0到part14,每個分割槽中包含的元素
//從hdfs檔案建立的rdd,包含65個分割槽,因為該檔案由65個block
scala> var rdd2 = sc.textfile("/logs/2015-07-05/lxw1234.com.log")
scala> rdd2.partitions.size
res18: int = 65
//rdd2每個分割槽的元素數量
? | (partidx,iter) => else
| iter.next()
| }
| part_map.iterator
|
| }
| }.collect
res19: array[(string, int)] = array((part_0,202496), (part_1,225503), (part_2,214375),
(part_3,215909), (part_4,208941), (part_5,205379), (part_6,207894), (part_7,209496),
(part_8,213806), (part_9,216962), (part_10,216091), (part_11,215820), (part_12,217043),
(part_13,216556), (part_14,218702), (part_15,218625), (part_16,218519), (part_17,221056),
(part_18,221250), (part_19,222092), (part_20,222339), (part_21,222779), (part_22,223578),
(part_23,222869), (part_24,221543), (part_25,219671), (part_26,222871), (part_27,223200),
(part_28,223282), (part_29,228212), (part_30,223978), (part_31,223024), (part_32,222889),
(part_33,222106), (part_34,221563), (part_35,219208), (part_36,216928), (part_37,216733),
(part_38,217214), (part_39,219978), (part_40,218155), (part_41,219880), (part_42,215833...
更多關於spark運算元的介紹,可參考 spark運算元 :
本文**所有權力歸原作者所有。
Spark運算元 統計RDD分割槽中的元素及數量
關鍵字 spark運算元 spark rdd分割槽 spark rdd分割槽元素數量 spark rdd是被分割槽的,在生成rdd時候,一般可以指定分割槽的數量,如果不指定分割槽數量,當rdd從集合建立時候,則預設為該程式所分配到的資源的cpu核數,如果是從hdfs檔案建立,預設為檔案的block數...
Spark運算元 統計RDD分割槽中的元素及數量
spark rdd是被分割槽的,在生成rdd時候,一般可以指定分割槽的數量,如果不指定分割槽數量,當rdd從集合建立時候,則預設為該程式所分配到的資源的cpu核數,如果是從hdfs檔案建立,預設為檔案的block數。具體看例子 建立乙個rdd,預設分割槽15個,因為我的spark shell指定了一...
Spark運算元 RDD分割槽中的元素和數量統計
1 分割槽邏輯 spark rdd是被分割槽的,在生成rdd時候,一般可以指定分割槽的數量,如果不指定分割槽數量,當rdd從集合建立時候,則預設為該程式所分配到的資源的cpu核數,如果是從hdfs檔案建立,預設為檔案的block數。2 分割槽元素統計 示例1 假如建立乙個rdd,預設分割槽15個,因...