nodes: 0, module; 1, function_definition; 2, function_name:groupByKey; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, function_definition; 10, function_definition; 11, function_definition; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, function_definition; 16, expression_statement; 17, expression_statement; 18, function_definition; 19, return_statement; 20, identifier:numPartitions; 21, None; 22, identifier:partitionFunc; 23, identifier:portable_hash; 24, comment:"""
          Group the values for each key in the RDD into a single sequence.
          Hash-partitions the resulting RDD with numPartitions partitions.
  
          .. note:: If you are grouping in order to perform an aggregation (such as a
              sum or average) over each key, using reduceByKey or aggregateByKey will
              provide much better performance.
  
          >>> rdd = sc.parallelize([("a", 1), ("b", 1), ("a", 1)])
          >>> sorted(rdd.groupByKey().mapValues(len).collect())
          [('a', 2), ('b', 1)]
          >>> sorted(rdd.groupByKey().mapValues(list).collect())
          [('a', [1, 1]), ('b', [1])]
          """; 25, function_name:createCombiner; 26, parameters; 27, block; 28, function_name:mergeValue; 29, parameters; 30, block; 31, function_name:mergeCombiners; 32, parameters; 33, block; 34, assignment; 35, assignment; 36, assignment; 37, function_name:combine; 38, parameters; 39, block; 40, assignment; 41, assignment; 42, function_name:groupByKey; 43, parameters; 44, block; 45, call; 46, identifier:x; 47, return_statement; 48, identifier:xs; 49, identifier:x; 50, expression_statement; 51, return_statement; 52, identifier:a; 53, identifier:b; 54, expression_statement; 55, return_statement; 56, identifier:memory; 57, call; 58, identifier:serializer; 59, attribute; 60, identifier:agg; 61, call; 62, identifier:iterator; 63, expression_statement; 64, expression_statement; 65, return_statement; 66, identifier:locally_combined; 67, call; 68, identifier:shuffled; 69, call; 70, identifier:it; 71, expression_statement; 72, expression_statement; 73, return_statement; 74, attribute; 75, argument_list; 76, list; 77, call; 78, identifier:xs; 79, call; 80, identifier:a; 81, attribute; 82, argument_list; 83, identifier:self; 84, identifier:_jrdd_deserializer; 85, identifier:Aggregator; 86, argument_list; 87, assignment; 88, call; 89, call; 90, attribute; 91, argument_list; 92, attribute; 93, argument_list; 94, assignment; 95, call; 96, call; 97, call; 98, identifier:mapValues; 99, identifier:ResultIterable; 100, identifier:x; 101, attribute; 102, argument_list; 103, attribute; 104, argument_list; 105, identifier:self; 106, identifier:_memory_limit; 107, identifier:createCombiner; 108, identifier:mergeValue; 109, identifier:mergeCombiners; 110, identifier:merger; 111, call; 112, attribute; 113, argument_list; 114, attribute; 115, argument_list; 116, identifier:self; 117, identifier:mapPartitions; 118, identifier:combine; 119, keyword_argument; 120, identifier:locally_combined; 121, identifier:partitionBy; 122, identifier:numPartitions; 123, identifier:partitionFunc; 124, identifier:merger; 125, call; 126, attribute; 127, argument_list; 128, attribute; 129, argument_list; 130, attribute; 131, argument_list; 132, identifier:xs; 133, identifier:append; 134, identifier:x; 135, identifier:a; 136, identifier:extend; 137, identifier:b; 138, identifier:ExternalMerger; 139, argument_list; 140, identifier:merger; 141, identifier:mergeValues; 142, identifier:iterator; 143, identifier:merger; 144, identifier:items; 145, identifier:preservesPartitioning; 146, True; 147, identifier:ExternalGroupBy; 148, argument_list; 149, identifier:merger; 150, identifier:mergeCombiners; 151, identifier:it; 152, identifier:merger; 153, identifier:items; 154, identifier:shuffled; 155, identifier:mapPartitions; 156, identifier:groupByKey; 157, True; 158, identifier:agg; 159, binary_operator:memory * 0.9; 160, identifier:serializer; 161, identifier:agg; 162, identifier:memory; 163, identifier:serializer; 164, identifier:memory; 165, float:0.9
code: def groupByKey(self, numPartitions=None, partitionFunc=portable_hash):
          """
          Group the values for each key in the RDD into a single sequence.
          Hash-partitions the resulting RDD with numPartitions partitions.
  
          .. note:: If you are grouping in order to perform an aggregation (such as a
              sum or average) over each key, using reduceByKey or aggregateByKey will
              provide much better performance.
  
          >>> rdd = sc.parallelize([("a", 1), ("b", 1), ("a", 1)])
          >>> sorted(rdd.groupByKey().mapValues(len).collect())
          [('a', 2), ('b', 1)]
          >>> sorted(rdd.groupByKey().mapValues(list).collect())
          [('a', [1, 1]), ('b', [1])]
          """
          def createCombiner(x):
              return [x]
  
          def mergeValue(xs, x):
              xs.append(x)
              return xs
  
          def mergeCombiners(a, b):
              a.extend(b)
              return a
  
          memory = self._memory_limit()
          serializer = self._jrdd_deserializer
          agg = Aggregator(createCombiner, mergeValue, mergeCombiners)
  
          def combine(iterator):
              merger = ExternalMerger(agg, memory * 0.9, serializer)
              merger.mergeValues(iterator)
              return merger.items()
  
          locally_combined = self.mapPartitions(combine, preservesPartitioning=True)
          shuffled = locally_combined.partitionBy(numPartitions, partitionFunc)
  
          def groupByKey(it):
              merger = ExternalGroupBy(agg, memory, serializer)
              merger.mergeCombiners(it)
              return merger.items()
  
          return shuffled.mapPartitions(groupByKey, True).mapValues(ResultIterable)