Ejemplo n.º 1
0
    def _test(self, lst):
        exp = list(group_by_simple(lst))

        def _(x):
            return list(map(list_value, x))

        nit1 = GroupByNestedIter(iter(lst))
        res1 = _(nit1)

        self.assertEqual(exp, res1, res1)
        self.assertFalse(nit1.is_cached)
        self.assertRaises(StopIteration, next, nit1)

        nit2 = GroupByNestedIter(iter(lst))
        res2 = list(nit2)
        res2 = _(res2)

        self.assertEqual(exp, res2, res2)
        self.assertRaises(StopIteration, next, nit2)
        if len(lst) > 1:
            self.assertTrue(nit2.is_cached, res2)

        if lst:
            nit3 = GroupByNestedIter(iter(lst))
            k1, vit1 = next(nit3)
            res3 = _(nit3)
            vs1 = list(vit1)
            self.assertRaises(StopIteration, next, vit1)
            res3 = [(k1, vs1)] + res3
            self.assertEqual(exp, res3, res3)
Ejemplo n.º 2
0
 def __iter__(self):
     if not self.archives:
         return six.iteritems(self.combined)
     items = self.combined.items()
     items.sort(key=itemgetter(0))
     combined = items
     self.archives.append(iter(combined))
     iters = list(map(iter, self.archives))
     if self.rddconf.is_groupby and self.rddconf.iter_group:
         heap = HeapOnKey(key=lambda x: x[0], min_heap=True)
         it = GroupByNestedIter(heap.merge(iters), "")
     else:
         it = heap_merged(iters, self._get_merge_function())
     return it
Ejemplo n.º 3
0
 def _merge_sorted(self, iters):
     heap = HeapOnKey(key=lambda x: x[0], min_heap=True)
     return GroupByNestedIter(heap.merge(iters), self.api_callsite)
Ejemplo n.º 4
0
 def _(i):
     v = list(range(i, 10, 3))
     lst = [('k1', v)] * 2 + [('k2', list(v))]
     return GroupByNestedIter(lst)