Example #1
0
    def __iter__(self):
        """Batch load and iterate over all objects in this view."""
        all_cols = self._cols()

        cols = [True]
        fetched = 0
        while len(cols) > 0:
            cols = tuple(islice(all_cols, self.chunk_size))
            fetched += len(cols)
            keys = tuple(self.make_key(col) for col in cols)
            recs = multigetterator(keys, self.consistency)

            if (self.record_key.keyspace not in recs
                or self.record_key.column_family not in
                recs[self.record_key.keyspace]):
                raise StopIteration()

            data = recs[self.record_key.keyspace][self.record_key.column_family]

            for (index, k) in enumerate(keys):
                record_data = data[k.key]
                if k.is_super():
                    record_data = record_data[k.super_column]

                self.last_col = cols[index]
                yield (self.record_class()._inject(
                        self.record_key.clone(key=k.key), record_data))
Example #2
0
    def __iter__(self):
        """Batch load and iterate over all objects in this view."""
        all_cols = self._cols()

        cols = [True]
        fetched = 0
        while len(cols) > 0:
            cols = tuple(islice(all_cols, self.chunk_size))
            fetched += len(cols)
            keys = tuple(self.make_key(col) for col in cols)
            recs = multigetterator(keys, self.consistency)

            if (self.record_key.keyspace not in recs
                or self.record_key.column_family not in
                recs[self.record_key.keyspace]):
                raise StopIteration()

            data = recs[self.record_key.keyspace][self.record_key.column_family]

            for (index, k) in enumerate(keys):
                record_data = data[k.key]
                if k.is_super():
                    record_data = record_data[k.super_column]

                self.last_col = cols[index]
                yield (self.record_class()._inject(
                        self.record_key.clone(key=k.key), record_data))
Example #3
0
 def _batch_load(self, record_class, keys):
     """Return an iterator of records for the given keys."""
     data = itr.multigetterator(keys, self.consistency)
     for (keyspace, col_fams) in data.iteritems():
         for (col_fam, rows) in col_fams.iteritems():
             for (row_key, cols) in rows.iteritems():
                 yield record_class()._inject(
                     Key(keyspace=keyspace, column_family=col_fam,
                         key=row_key), cols)
Example #4
0
 def _batch_load(self, record_class, keys, consistency=None):
     """Return an iterator of records for the given keys."""
     consistency = consistency or self.consistency
     data = itr.multigetterator(keys, consistency)
     for (keyspace, col_fams) in data.iteritems():
         for (col_fam, rows) in col_fams.iteritems():
             for (row_key, cols) in rows.iteritems():
                 yield record_class()._inject(
                     Key(keyspace=keyspace,
                         column_family=col_fam,
                         key=row_key), cols)
Example #5
0
    def test_multigetterator(self):
        """Test multigetterator."""
        keys = [Key("eggs", "bacon", "cleese"),
                Key("eggs", "bacon", "gilliam"),
                Key("eggs", "spam", "jones"),
                Key("eggs", "spam", "idle"),
                Key("tomato", "sausage", "chapman"),
                Key("tomato", "sausage", "palin")]

        def pack(cols):
            return list(iterators.pack(cols))

        data = {'eggs': # Keyspace
                {'bacon': # Column Family
                 {'cleese': pack([Column(name="john", value="cleese")]),
                  'gilliam': pack([Column(name="terry", value="gilliam")])},
                 'spam': # Column Family
                 {'jones': pack([Column(name="terry", value="jones")]),
                  'idle': pack([Column(name="eric", value="idle")])}},
                'tomato': # Keyspace
                {'sausage': # Column Family
                 {'chapman':
                      pack([SuperColumn(name="chap_scol", columns=[])]),
                  'palin':
                      pack([SuperColumn(name="pal_scol", columns=[])])}}}

        def gen_ms(keyspace):
            def multiget_slice(keys, column_parent, predicate,
                               consistencylevel):
                return data[keyspace][column_parent.column_family]
            return multiget_slice
        
        for keyspace in ("eggs", "tomato"):
            self.clients[keyspace].multiget_slice = gen_ms(keyspace)

        res = iterators.multigetterator(keys, ConsistencyLevel.ONE)
        self.assert_(isinstance(res, dict))
        for (keyspace, col_fams) in res.iteritems():
            self.assert_(keyspace in res)
            self.assert_(isinstance(col_fams, dict))
            for (col_fam, rows) in col_fams.iteritems():
                self.assert_(col_fam in data[keyspace])
                self.assert_(isinstance(rows, dict))
                for (row_key, columns) in rows.iteritems():
                    self.assert_(row_key in data[keyspace][col_fam])
                    for column in columns:
                        if keyspace == 'tomato':
                            self.assert_(isinstance(column, SuperColumn))
                        else:
                            self.assert_(isinstance(column, Column))
Example #6
0
    def __iter__(self):
        """Batch load and iterate over all objects in this view."""
        keys = tuple(self._keys())
        recs = multigetterator(keys, self.consistency)

        if (self.record_key.keyspace not in recs
            or self.record_key.column_family not in
            recs[self.record_key.keyspace]):
            raise StopIteration()

        data = recs[self.record_key.keyspace][self.record_key.column_family]

        for k in keys:
            yield (self.record_class()._inject(
                self.record_key.clone(key=k.key), data[k.key]))