Exemplo n.º 1
0
    def _slice_predicate(self,
                         columns,
                         column_start,
                         column_finish,
                         column_reversed,
                         column_count,
                         super_column=None,
                         pack=True):
        is_supercol_name = self.super and super_column is None
        if columns is not None:
            packed_cols = []
            for col in columns:
                packed_cols.append(
                    self._pack_name(col, is_supercol_name=is_supercol_name))
            return SlicePredicate(column_names=packed_cols)
        else:
            if column_start != '' and pack:
                column_start = self._pack_name(
                    column_start,
                    is_supercol_name=is_supercol_name,
                    slice_start=(not column_reversed))
            if column_finish != '' and pack:
                column_finish = self._pack_name(
                    column_finish,
                    is_supercol_name=is_supercol_name,
                    slice_start=column_reversed)

            sr = SliceRange(start=column_start,
                            finish=column_finish,
                            reversed=column_reversed,
                            count=column_count)
            return SlicePredicate(slice_range=sr)
Exemplo n.º 2
0
    def _create_slice_predicate(self,
                                columns,
                                column_start,
                                column_finish,
                                column_reversed,
                                column_count,
                                super_column=None):
        is_supercol_name = self.super and super_column is None
        if columns is not None:
            packed_cols = []
            for col in columns:
                packed_cols.append(
                    self._pack_name(col, is_supercol_name=is_supercol_name))
            return SlicePredicate(column_names=packed_cols)
        else:
            if column_start != '':
                column_start = self._pack_name(
                    column_start,
                    is_supercol_name=is_supercol_name,
                    slice_end=_SLICE_START)
            if column_finish != '':
                column_finish = self._pack_name(
                    column_finish,
                    is_supercol_name=is_supercol_name,
                    slice_end=_SLICE_FINISH)

            sr = SliceRange(start=column_start,
                            finish=column_finish,
                            reversed=column_reversed,
                            count=column_count)
            return SlicePredicate(slice_range=sr)
Exemplo n.º 3
0
def create_SlicePredicate(columns, column_start, column_finish,
                          column_reversed, column_count):
    if columns is not None:
        return SlicePredicate(column_names=columns)
    sr = SliceRange(start=column_start,
                    finish=column_finish,
                    reversed=column_reversed,
                    count=column_count)
    return SlicePredicate(slice_range=sr)
Exemplo n.º 4
0
    def remove(self,
               column_family,
               key,
               columns=None,
               super_column=None,
               timestamp=None):
        """
        Adds a single row remove to the batch.

        `column_family` is the :class:`~pycassa.columnfamily.ColumnFamily`
        that the remove will be executed on.

        """
        if timestamp is None:
            timestamp = column_family.timestamp()
        deletion = Deletion(timestamp=timestamp)
        _pack_name = column_family._pack_name
        if super_column is not None:
            deletion.super_column = _pack_name(super_column, True)
        if columns is not None:
            is_super = column_family.super and super_column is None
            packed_cols = [_pack_name(col, is_super) for col in columns]
            deletion.predicate = SlicePredicate(column_names=packed_cols)
        mutation = Mutation(deletion=deletion)
        packed_key = column_family._pack_key(key)
        self._enqueue(packed_key, column_family, (mutation, ))
        return self
Exemplo n.º 5
0
def slice_iterator(key, consistency, **predicate_args):
    """Return an iterator over a row."""

    predicate = SlicePredicate()
    if "columns" in predicate_args:
        predicate.column_names = predicate_args["columns"]
    else:
        args = {"start": "", "finish": "", "count": 100000, "reversed": False}
        args.update(predicate_args)
        predicate.slice_range = SliceRange(**args)

    consistency = consistency or ConsistencyLevel.ONE

    client = get_pool(key.keyspace)
    res = client.get_slice(key.key, key, predicate, consistency)

    if not res:
        raise exc.ErrorNoSuchRecord("No record matching key %s" % key)

    return unpack(res)
Exemplo n.º 6
0
 def remove(self,
            column_family,
            key,
            columns=None,
            super_column=None,
            timestamp=None):
     if timestamp == None:
         timestamp = column_family.timestamp()
     deletion = Deletion(timestamp=timestamp)
     if columns:
         _pack_name = column_family._pack_name
         packed_cols = [
             _pack_name(col, column_family.super) for col in columns
         ]
         deletion.predicate = SlicePredicate(column_names=packed_cols)
         if super_column:
             deletion.super_column = super_column
     mutation = Mutation(deletion=deletion)
     self._enqueue(key, column_family, (mutation, ))
     return self