def group_by_key(num_partitions=nil)
      create_combiner = 'lambda{|item| [item]}'
      merge_value     = 'lambda{|combiner, item| combiner << item; combiner}'
      merge_combiners = 'lambda{|combiner_1, combiner_2| combiner_1 += combiner_2; combiner_1}'

      combine_by_key(create_combiner, merge_value, merge_combiners, num_partitions)
    end
def group_by_key(num_partitions=nil)
      create_combiner = 'lambda{|item| [item]}'
      merge_value     = 'lambda{|combiner, item| combiner << item; combiner}'
      merge_combiners = 'lambda{|combiner_1, combiner_2| combiner_1 += combiner_2; combiner_1}'

      combine_by_key(create_combiner, merge_value, merge_combiners, num_partitions)
    end
Group the values for each key in the RDD into a single sequence. Allows controlling the
 partitioning of the resulting key-value pair RDD by passing a Partitioner.

 Note: If you are grouping in order to perform an aggregation (such as a sum or average)
 over each key, using reduce_by_key or combine_by_key will provide much better performance.

 == Example:
   rdd = $sc.parallelize([["a", 1], ["a", 2], ["b", 3]])
   rdd.group_by_key.collect
   # => [["a", [1, 2]], ["b", [3]]]