aggregateByKey(zeroValue)(seqOp, combOp, [numTasks])

aggregateByKey(zeroValue)(seqOp, combOp, [numTasks]) When called on a dataset of (K, V) pairs, returns a dataset of (K, U) pairs where the values for each key are aggregated using the given combine functions and a neutral "zero" value. Allows an aggregated value type that is different than the input value type, while avoiding unnecessary allocations. Like in groupByKey, the number of reduce tasks is configurable through an optional second argument. 
  1.  
  1. /**
    * Aggregate the values of each key, using given combine functions and a neutral "zero value".
    * This function can return a different result type, U, than the type of the values in this RDD,
    * V. Thus, we need one operation for merging a V into a U and one operation for merging two U's,
    * as in scala.TraversableOnce. The former operation is used for merging values within a
    * partition, and the latter is used for merging values between partitions. To avoid memory
    * allocation, both of these functions are allowed to modify and return their first argument
    * instead of creating a new U.
    */
    def aggregateByKey[U: ClassTag](zeroValue: U)(seqOp: (U, V) => U,
    combOp: (U, U) => U): RDD[(K, U)]
  1. /**
    * Aggregate the values of each key, using given combine functions and a neutral "zero value".
    * This function can return a different result type, U, than the type of the values in this RDD,
    * V. Thus, we need one operation for merging a V into a U and one operation for merging two U's,
    * as in scala.TraversableOnce. The former operation is used for merging values within a
    * partition, and the latter is used for merging values between partitions. To avoid memory
    * allocation, both of these functions are allowed to modify and return their first argument
    * instead of creating a new U.
    */
    def aggregateByKey[U: ClassTag](zeroValue: U, numPartitions: Int)(seqOp: (U, V) => U,
    combOp: (U, U) => U): RDD[(K, U)]
  1. /**
    * Aggregate the values of each key, using given combine functions and a neutral "zero value".
    * This function can return a different result type, U, than the type of the values in this RDD,
    * V. Thus, we need one operation for merging a V into a U and one operation for merging two U's,
    * as in scala.TraversableOnce. The former operation is used for merging values within a
    * partition, and the latter is used for merging values between partitions. To avoid memory
    * allocation, both of these functions are allowed to modify and return their first argument
    * instead of creating a new U.
    */
    def aggregateByKey[U: ClassTag](zeroValue: U, partitioner: Partitioner)(seqOp: (U, V) => U,
    combOp: (U, U) => U): RDD[(K, U)]
  1. def seq(a:Int,b:Int):Int={
  2. println("seq: " + a + "\t" + b)
  3. math.max(a,b)
  4. }
  5.  
  6. def comb(a:Int,b:Int):Int = {
  7. println("comb: " + a + "\t" + b)
  8. a+b
  9. }
  10.  
  11. val rdd = sc.parallelize(List((1,3),(1,2),(1,4),(2,3),(2,4),(2,5)))
  12. rdd.aggregateByKey(0)(seq,comb).collect
  13. rdd.aggregateByKey(6)(seq,comb).collect
  1. scala> def seq(a:Int,b:Int):Int={
  2. | println("seq: " + a + "\t" + b)
  3. | math.max(a,b)
  4. | }
  5. seq: (a: Int, b: Int)Int
  6.  
  7. scala>
  8.  
  9. scala> def comb(a:Int,b:Int):Int = {
  10. | println("comb: " + a + "\t" + b)
  11. | a+b
  12. | }
  13. comb: (a: Int, b: Int)Int
  14. scala> val rdd = sc.parallelize(List((1,3),(1,2),(1,4),(2,3),(2,4),(2,5)))
  15. rdd: org.apache.spark.rdd.RDD[(Int, Int)] = ParallelCollectionRDD[11] at parallelize at <console>:26
  16.  
  17. scala> rdd.aggregateByKey(0)(seq,comb).collect
  18. seq: 0 3
  19. seq: 3 2
  20. seq: 3 4
  21. seq: 0 3
  22. seq: 3 4
  23. seq: 4 5
  24. res20: Array[(Int, Int)] = Array((1,4), (2,5))
  25.  
  26. scala> rdd.aggregateByKey(6)(seq,comb).collect
  27. seq: 6 3
  28. seq: 6 2
  29. seq: 6 4
  30. seq: 6 3
  31. seq: 6 4
  32. seq: 6 5
  33. res21: Array[(Int, Int)] = Array((1,6), (2,6))

但是为什么没有执行comb呢?

sortByKey([ascending], [numTasks])

sortByKey([ascending], [numTasks]) When called on a dataset of (K, V) pairs where K implements Ordered, returns a dataset of (K, V) pairs sorted by keys in ascending or descending order, as specified in the boolean ascending argument.
  1. 从下面的注释中可以看到在每一个partition中元素是有序的,但是在整个rdd中数据可能是无序的。
    /**
    * Sort the RDD by key, so that each partition contains a sorted range of the elements. Calling
    * `collect` or `save` on the resulting RDD will return or output an ordered list of records
    * (in the `save` case, they will be written to multiple `part-X` files in the filesystem, in
    * order of the keys).
    */
    // TODO: this currently doesn't work on P other than Tuple2!
    def sortByKey(ascending: Boolean = true, numPartitions: Int = self.partitions.length)
    : RDD[(K, V)]
  1. val rdd = sc.parallelize(List((3,"sd"),(1,"fd"),(2,"dfh"),(4,"kjh"),(7,"kf"),(5,"nb"),(100,"jd"),(63,"mm"),(42,"kk"),(99,"ll"),(10,"ll"),(11,"ll"),(12,"ll")),1)
  2. val rdd1 = rdd.sortByKey(true,1)
  3. rdd1.collect
  4. val rdd2 = rdd.sortByKey(true,3)
  5. rdd2.foreachPartition(
  6. x=>{
  7. while(x.hasNext){
  8. println(x.next)
  9. }
  10. println("============")
  11. }
  12. )
  13.  
  14. val rdd2 = rdd.sortByKey(false,4)
  15. val rdd2 = rdd.sortByKey(true,3)
  16. rdd2.foreachPartition(
  17. x=>{
  18. while(x.hasNext){
  19. println(x.next)
  20. }
  21. println("============")
  22. }
  23. )
  1. scala> val rdd = sc.parallelize(List((3,"sd"),(1,"fd"),(2,"dfh"),(4,"kjh"),(7,"kf"),(5,"nb"),(100,"jd"),(63,"mm"),(42,"kk"),(99,"ll"),(10,"ll"),(11,"ll"),(12,"ll")),1)
  2. rdd: org.apache.spark.rdd.RDD[(Int, String)] = ParallelCollectionRDD[24] at parallelize at <console>:26
  3.  
  4. scala> val rdd1 = rdd.sortByKey(true,1)
  5. rdd1: org.apache.spark.rdd.RDD[(Int, String)] = ShuffledRDD[25] at sortByKey at <console>:28
  6.  
  7. scala> rdd1.collect
  8. res42: Array[(Int, String)] = Array((1,fd), (2,dfh), (3,sd), (4,kjh), (5,nb), (7,kf), (10,ll), (11,ll), (12,ll), (42,kk), (63,mm), (99,ll), (100,jd))
  9.  
  10. scala> val rdd2 = rdd.sortByKey(true,3)
  11. rdd2: org.apache.spark.rdd.RDD[(Int, String)] = ShuffledRDD[28] at sortByKey at <console>:28
  12.  
  13. scala> rdd2.foreachPartition(
  14. | x=>{
  15. | while(x.hasNext){
  16. | println(x.next)
  17. | }
  18. | println("============")
  19. | }
  20. | )
  21. (1,fd)
  22. (2,dfh)
  23. (3,sd)
  24. (4,kjh)
  25. (5,nb)
  26. ============
  27. (7,kf)
  28. (10,ll)
  29. (11,ll)
  30. (12,ll)
  31. ============
  32. (42,kk)
  33. (63,mm)
  34. (99,ll)
  35. (100,jd)
  36. ============
  37.  
  38. scala> val rdd2 = rdd.sortByKey(false,4)
  39. rdd2: org.apache.spark.rdd.RDD[(Int, String)] = ShuffledRDD[34] at sortByKey at <console>:28
  40.  
  41. scala> rdd2.foreachPartition(
  42. | x=>{
  43. | while(x.hasNext){
  44. | println(x.next)
  45. | }
  46. | println("============")
  47. | }
  48. | )
  49. (100,jd)
  50. (99,ll)
  51. (63,mm)
  52. ============
  53. (42,kk)
  54. (12,ll)
  55. (11,ll)
  56. ============
  57. (10,ll)
  58. (7,kf)
  59. (5,nb)
  60. ============
  61. (4,kjh)
  62. (3,sd)
  63. (2,dfh)
  64. (1,fd)
  65. ============

sortBy(func,[ascending], [numTasks])

  1. /**
    * Return this RDD sorted by the given key function.
    */
    def sortBy[K](
    f: (T) => K,
    ascending: Boolean = true,
    numPartitions: Int = this.partitions.length)
    (implicit ord: Ordering[K], ctag: ClassTag[K]): RDD[T]
  1. val a = Array(9,2,8,1,5,6,4,7,3)
  2. val rdd = sc.parallelize(a)
  3. rdd.collect
  4. rdd.sortBy(x=>x).collect
  5. rdd.sortBy(x=>x,false,3).collect
  1. scala> val a = Array(9,2,8,1,5,6,4,7,3)
  2. a: Array[Int] = Array(9, 2, 8, 1, 5, 6, 4, 7, 3)
  3.  
  4. scala> val rdd = sc.parallelize(a)
  5. rdd: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[35] at parallelize at <console>:28
  6.  
  7. scala> rdd.collect
  8. res46: Array[Int] = Array(9, 2, 8, 1, 5, 6, 4, 7, 3)
  9.  
  10. scala> rdd.sortBy(x=>x).collect
  11. res49: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9)
  12.  
  13. scala> rdd.sortBy(x=>x,false,3).collect
  14. res50: Array[Int] = Array(9, 8, 7, 6, 5, 4, 3, 2, 1)

join(otherDataset, [numTasks])

join(otherDataset, [numTasks]) When called on datasets of type (K, V) and (K, W), returns a dataset of (K, (V, W)) pairs with all pairs of elements for each key. Outer joins are supported through leftOuterJoin, rightOuterJoin, and fullOuterJoin

同SQL语句中join,leftOuterJoin同SQL中left outer join,rightOuterJoin同SQL语句中right outer join,fullOuterJoin同SQL语句中的full outer join

  1. scala> val a = List((1,"a"),(2,"b"),(3,"c"))
  2. a: List[(Int, String)] = List((1,a), (2,b), (3,c))
  3.  
  4. scala> val rdd1 = sc.parallelize(a)
  5. rdd1: org.apache.spark.rdd.RDD[(Int, String)] = ParallelCollectionRDD[47] at parallelize at <console>:28
  6.  
  7. scala> val b = List((1,"A"),(2,"B"),(4,"D"))
  8. b: List[(Int, String)] = List((1,A), (2,B), (4,D))
  9.  
  10. scala> val rdd2 = sc.parallelize(b)
  11. rdd2: org.apache.spark.rdd.RDD[(Int, String)] = ParallelCollectionRDD[48] at parallelize at <console>:28
  12.  
  13. scala> val rdd = rdd1.join(rdd2)
  14. rdd: org.apache.spark.rdd.RDD[(Int, (String, String))] = MapPartitionsRDD[51] at join at <console>:34
  15.  
  16. scala> rdd.collect
  17. res51: Array[(Int, (String, String))] = Array((1,(a,A)), (2,(b,B)))
  18.  
  19. scala> rdd1.leftOuterJoin(rdd2)
  20. res52: org.apache.spark.rdd.RDD[(Int, (String, Option[String]))] = MapPartitionsRDD[54] at leftOuterJoin at <console>:35
  21.  
  22. scala> rdd1.leftOuterJoin(rdd2).collect
  23. res53: Array[(Int, (String, Option[String]))] = Array((1,(a,Some(A))), (3,(c,None)), (2,(b,Some(B))))
  24.  
  25. scala> rdd1.rightOuterJoin(rdd2).collect
  26. res54: Array[(Int, (Option[String], String))] = Array((4,(None,D)), (1,(Some(a),A)), (2,(Some(b),B)))
  27.  
  28. scala> rdd1.fullOuterJoin(rdd2).collect
  29. res55: Array[(Int, (Option[String], Option[String]))] = Array((4,(None,Some(D))), (1,(Some(a),Some(A))), (3,(Some(c),None)), (2,(Some(b),Some(B))))

不管是join,leftOuterJoin,rightOuterJoin还是fullOuterJoin,除上述入参为otherDataset外,还包含下面两种方式

  1. (other: RDD[(K, W)], numPartitions: Int)
  1. (other: RDD[(K, W)], partitioner: Partitioner)

cogroup(otherDataset, [numTasks])

cogroup(otherDataset, [numTasks]) When called on datasets of type (K, V) and (K, W), returns a dataset of (K, (Iterable<V>, Iterable<W>)) tuples. This operation is also called groupWith
  1.  
  1. /**
    * For each key k in `this` or `other`, return a resulting RDD that contains a tuple with the
    * list of values for that key in `this` as well as `other`.
    */
    def cogroup[W](other: RDD[(K, W)]): RDD[(K, (Iterable[V], Iterable[W]))]
  1. scala> val rdd1 = sc.parallelize(List((1,"a"),(2,"b"),(3,"c"),(1,"z")))
  2. rdd1: org.apache.spark.rdd.RDD[(Int, String)] = ParallelCollectionRDD[0] at parallelize at <console>:24
  3.  
  4. scala> val rdd2 = sc.parallelize(List((1,"A"),(2,"B"),(2,"C"),(4,"D")))
  5. rdd2: org.apache.spark.rdd.RDD[(Int, String)] = ParallelCollectionRDD[1] at parallelize at <console>:24
  6.  
  7. scala> val rdd = rdd1.cogroup(rdd2)
  8. rdd: org.apache.spark.rdd.RDD[(Int, (Iterable[String], Iterable[String]))] = MapPartitionsRDD[3] at cogroup at <console>:28
  9.  
  10. scala> rdd.collect
  11. res0: Array[(Int, (Iterable[String], Iterable[String]))] = Array((4,(CompactBuffer(),CompactBuffer(D))), (1,(CompactBuffer(a, z),CompactBuffer(A))), (3,(CompactBuffer(c),CompactBuffer())), (2,(CompactBuffer(b),CompactBuffer(B, C))))

cartesian(otherDataset)

cartesian(otherDataset) When called on datasets of types T and U, returns a dataset of (T, U) pairs (all pairs of elements). 
  1. 对两个RDD中元素进行笛卡尔积运算。
  2.  
  3. /**
    * Return the Cartesian product of this RDD and another one, that is, the RDD of all pairs of
    * elements (a, b) where a is in `this` and b is in `other`.
    */
    def cartesian[U: ClassTag](other: RDD[U]): RDD[(T, U)]
  1. scala> val rdd1 = sc.parallelize(Array(1,2,3,4,5))
  2. rdd1: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[4] at parallelize at <console>:24
  3.  
  4. scala> val rdd2 = sc.parallelize(Array("A","B","C"))
  5. rdd2: org.apache.spark.rdd.RDD[String] = ParallelCollectionRDD[5] at parallelize at <console>:24
  6.  
  7. scala> val rdd = rdd1.cartesian(rdd2)
  8. rdd: org.apache.spark.rdd.RDD[(Int, String)] = CartesianRDD[6] at cartesian at <console>:28
  9.  
  10. scala> rdd.collect
  11. res1: Array[(Int, String)] = Array((1,A), (1,B), (1,C), (2,A), (2,B), (2,C), (3,A), (3,B), (3,C), (4,A), (4,B), (4,C), (5,A), (5,B), (5,C))

pipe(command, [envVars])

pipe(command, [envVars]) Pipe each partition of the RDD through a shell command, e.g. a Perl or bash script. RDD elements are written to the process's stdin and lines output to its stdout are returned as an RDD of strings. 
  1. 通过pipe运行外部程序,每个分区中的元素作为外部程序入参运行一次外部程序,而外部程序的输出有创建一个新的RDD
    /**
    * Return an RDD created by piping elements to a forked external process.
    */
    def pipe(command: String): RDD[String]
  1. [root@localhost home]# more /home/test.sh
  2. #!/bin/bash
  3. echo "Running shell script"
  4. RESULT=""
  5. while read LINE
  6. do
  7. if [ -z ${LINE} ]
  8. then
  9. break
  10. fi
  11. RESULT=${RESULT}" "${LINE}
  12. done
  13.  
  14. echo ${RESULT} >> /home/out.txt
  15. echo "========" >>/home/out.txt
  1. val rdd = sc.parallelize(List("ab","cd","ef","gh","ij"),)
  2. rdd.pipe("/home/test.sh").collect

结果:

rdd有两个分区,test.sh每次运行会输出一个“Running shell script”字符串,元素输出至/home/out.txt中。

  1. scala> val rdd = sc.parallelize(List("ab","cd","ef","gh","ij"),)
  2. rdd: org.apache.spark.rdd.RDD[String] = ParallelCollectionRDD[] at parallelize at <console>:
  3.  
  4. scala> rdd.pipe("/home/test.sh").collect
  5. res6: Array[String] = Array(Running shell script, Running shell script)
  1. [root@localhost home]# more out.txt
  2. ab cd
  3. ========
  4. ef gh ij
  5. ========

coalesce(numPartitions)

coalesce(numPartitions) Decrease the number of partitions in the RDD to numPartitions. Useful for running operations more efficiently after filtering down a large dataset. 
  1. 减少RDDpartition数量,对过滤掉大量数据后进行算子操作高效运行非常有用。
  2.  
  3. /**
    * Return a new RDD that is reduced into `numPartitions` partitions.
    *
    * This results in a narrow dependency, e.g. if you go from 1000 partitions
    * to 100 partitions, there will not be a shuffle, instead each of the 100
    * new partitions will claim 10 of the current partitions.
    *
    * However, if you're doing a drastic coalesce, e.g. to numPartitions = 1,
    * this may result in your computation taking place on fewer nodes than
    * you like (e.g. one node in the case of numPartitions = 1). To avoid this,
    * you can pass shuffle = true. This will add a shuffle step, but means the
    * current upstream partitions will be executed in parallel (per whatever
    * the current partitioning is).
    *
    * Note: With shuffle = true, you can actually coalesce to a larger number
    * of partitions. This is useful if you have a small number of partitions,
    * say 100, potentially with a few partitions being abnormally large. Calling
    * coalesce(1000, shuffle = true) will result in 1000 partitions with the
    * data distributed using a hash partitioner.
    */
    def coalesce(numPartitions: Int, shuffle: Boolean = false,
    partitionCoalescer: Option[PartitionCoalescer] = Option.empty)
    (implicit ord: Ordering[T] = null)
    : RDD[T]
  1. scala> val rdd = sc.parallelize(1 to 1000,1000)
  2. rdd: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[10] at parallelize at <console>:24
  3.  
  4. scala> val rdd1 = rdd.filter(_%3 == 0)
  5. rdd1: org.apache.spark.rdd.RDD[Int] = MapPartitionsRDD[11] at filter at <console>:26
  6.  
  7. scala> rdd1.partitions.length
  8. res7: Int = 1000
  9.  
  10. scala> rdd1.coalesce(3,false).partitions.length
  11. res9: Int = 3

repartition(numPartitions)

repartition(numPartitions) Reshuffle the data in the RDD randomly to create either more or fewer partitions and balance it across them. This always shuffles all data over the network. 
  1. 该函数其实内部调用就是coalesce(numPartitions, shuffle = true)。
  1. /**
    * Return a new RDD that has exactly numPartitions partitions.
    * Can increase or decrease the level of parallelism in this RDD. Internally, this uses
    * a shuffle to redistribute data.
    * If you are decreasing the number of partitions in this RDD, consider using `coalesce`,
    * which can avoid performing a shuffle.
    */
    def repartition(numPartitions: Int)(implicit ord: Ordering[T] = null): RDD[T] = withScope {
    coalesce(numPartitions, shuffle = true)
    }
  1. repartitionAndSortWithinPartitions(partitioner)
  1.  
repartitionAndSortWithinPartitions(partitioner) Repartition the RDD according to the given partitioner and, within each resulting partition, sort records by their keys. This is more efficient than calling repartition and then sorting within each partition because it can push the sorting down into the shuffle machinery. 
  1. /**
    * Repartition the RDD according to the given partitioner and, within each resulting partition,
    * sort records by their keys.
    *
    * This is more efficient than calling `repartition` and then sorting within each partition
    * because it can push the sorting down into the shuffle machinery.
    */
    def repartitionAndSortWithinPartitions(partitioner: Partitioner): RDD[(K, V)]
  1. class MyPartitioner(numParts:Int) extends org.apache.spark.Partitioner{
  2. override def numPartitions: Int = numParts
  3. override def getPartition(key: Any): Int = {
  4. key.toString.toInt%numPartitions
  5. }
  6. }
  7.  
  8. val rdd1 = sc.makeRDD(1 to 10,2)
  9. val rdd2 = sc.makeRDD(1 to 10,2)
  10. val rdd = rdd1.zip(rdd2)
  11.  
  12. rdd.foreachPartition(
  13. x=>{
  14. while(x.hasNext){
  15. println(x.next)
  16. }
  17. println("============")
  18. }
  19. )
  20.  
  21. val rdd3 = rdd.repartitionAndSortWithinPartitions(new MyPartitioner(3))
  22.  
  23. rdd3.foreachPartition(
  24. x=>{
  25. while(x.hasNext){
  26. println(x.next)
  27. }
  28. println("============")
  29. }
  30. )
  1. scala> class MyPartitioner(numParts:Int) extends org.apache.spark.Partitioner{
  2. | override def numPartitions: Int = numParts
  3. | override def getPartition(key: Any): Int = {
  4. | key.toString.toInt%numPartitions
  5. | }
  6. | }
  7. defined class MyPartitioner
  8.  
  9. scala> val rdd1 = sc.makeRDD(1 to 10,2)
  10. rdd1: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[37] at makeRDD at <console>:24
  11.  
  12. scala> val rdd2 = sc.makeRDD(1 to 10,2)
  13. rdd2: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[38] at makeRDD at <console>:24
  14.  
  15. scala> val rdd = rdd1.zip(rdd2)
  16. rdd: org.apache.spark.rdd.RDD[(Int, Int)] = ZippedPartitionsRDD2[39] at zip at <console>:28
  17.  
  18. scala> rdd.foreachPartition(
  19. | x=>{
  20. | while(x.hasNext){
  21. | println(x.next)
  22. | }
  23. | println("============")
  24. | }
  25. | )
  26. (1,1)
  27. (2,2)
  28. (3,3)
  29. (4,4)
  30. (5,5)
  31. ============
  32. (6,6)
  33. (7,7)
  34. (8,8)
  35. (9,9)
  36. (10,10)
  37. ============
  38.  
  39. scala> val rdd3 = rdd.repartitionAndSortWithinPartitions(new MyPartitioner(3))
  40. rdd3: org.apache.spark.rdd.RDD[(Int, Int)] = ShuffledRDD[40] at repartitionAndSortWithinPartitions at <console>:31
  41.  
  42. scala> rdd3.foreachPartition(
  43. | x=>{
  44. | while(x.hasNext){
  45. | println(x.next)
  46. | }
  47. | println("============")
  48. | }
  49. | )
  50. [Stage 17:> (0 + 1) / 3](3,3)
  51. (6,6)
  52. (9,9)
  53. ============
  54. (1,1)
  55. (4,4)
  56. (7,7)
  57. (10,10)
  58. ============
  59. (2,2)
  60. (5,5)
  61. (8,8)
  62. ============
  1.  

Spark RDD Transformation 简单用例(二)的更多相关文章

  1. Spark RDD Transformation 简单用例(三)

    cache和persist 将RDD数据进行存储,persist(newLevel: StorageLevel)设置了存储级别,cache()和persist()是相同的,存储级别为MEMORY_ON ...

  2. Spark RDD Action 简单用例(二)

    foreach(f: T => Unit) 对RDD的所有元素应用f函数进行处理,f无返回值./** * Applies a function f to all elements of this ...

  3. Spark RDD Transformation 简单用例(一)

    map(func) /** * Return a new RDD by applying a function to all elements of this RDD. */ def map[U: C ...

  4. Spark RDD Action 简单用例(一)

    collectAsMap(): Map[K, V] 返回key-value对,key是唯一的,如果rdd元素中同一个key对应多个value,则只会保留一个./** * Return the key- ...

  5. spark RDD transformation与action函数整理

    1.创建RDD val lines = sc.parallelize(List("pandas","i like pandas")) 2.加载本地文件到RDD ...

  6. spark rdd Transformation和Action 剖析

    1.看到 这篇总结的这么好, 就悄悄的转过来,供学习 wordcount.toDebugString查看RDD的继承链条 所以广义的讲,对任何函数进行某一项操作都可以认为是一个算子,甚至包括求幂次,开 ...

  7. PHP 下基于 php-amqp 扩展的 RabbitMQ 简单用例 (二) -- Topic Exchange 和 Fanout Exchange

    Topic Exchange 此模式下交换机,在推送消息时, 会根据消息的主题词和队列的主题词决定将消息推送到哪个队列. 交换机只会为 Queue 分发符合其指定的主题的消息. 向交换机发送消息时,消 ...

  8. spring事务详解(二)简单样例

    系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...

  9. Spark基础:(二)Spark RDD编程

    1.RDD基础 Spark中的RDD就是一个不可变的分布式对象集合.每个RDD都被分为多个分区,这些分区运行在分区的不同节点上. 用户可以通过两种方式创建RDD: (1)读取外部数据集====> ...

随机推荐

  1. Android之官方导航栏ActionBar

    一.ActionBar概述 ActionBar是android3.0以后新增的组件,主要用于标示应用程序以及用户所处的位置并提供相关操作以及全局的导航功能.下面我们就看看如何使用ActionBar,真 ...

  2. zeromq学习笔记1——centos下安装 zeromq-4.1.2

    1.前言 MQ(message queue)是消息队列的简称,可在多个线程.内核和主机盒之间弹性伸缩.ZMQ的明确目标是“成为标准网络协议栈的一部分,之后进入Linux内核”.现在还未看到它们的成功. ...

  3. js手机适配

    代码一: <script type="text/javascript"> function mobile_device_detect(url){ var thisOS= ...

  4. grep 多行 正则匹配

    https://stackoverflow.com/questions/2686147/how-to-find-patterns-across-multiple-lines-using-grep I ...

  5. 移除list中null元素

    查询结果为null, list.size()却是1 移除该null元素 totalList.removeAll(Collections.singleton(null));

  6. Buffering of C streams

    This chapter describes buffering modes used by z/OS XL C/C++ library functions available to control ...

  7. JAVA中对List<Map<String,Object>>中的中文汉字进行排序

    转载于:http://blog.csdn.net/flykos/article/details/54631573 参考:http://www.jb51.net/article/88710.htm 本篇 ...

  8. Android 得到照片位置信息

    目前Android SDK定义的Tag有:TAG_DATETIME    时间日期TAG_FLASH   闪光灯TAG_GPS_LATITUDE   纬度TAG_GPS_LATITUDE_REF  纬 ...

  9. NodeJs相关系列文章

    1.图片上传之FileAPI与NodeJs 2.NodeJs之调试 3.CentOS下使用NVM 4.NodeJs之进程守护 5.Ubuntu下使用nvm 6.NodeJs之pm2 7.NodeJs之 ...

  10. java实现urlencode

    https://www.cnblogs.com/del88/p/6496825.html ****************************************************** ...