20
20
def __init__(self, table, timestamp=None, batch_size=None,
21
transaction=False, wal=True):
22
22
"""Initialise a new Batch instance."""
23
23
if not (timestamp is None or isinstance(timestamp, Integral)):
24
24
raise TypeError("'timestamp' must be an integer or None")
51
52
logger.debug("Sending batch for '%s' (%d mutations on %d rows)",
52
53
self._table.name, self._mutation_count, len(bms))
53
54
if self._timestamp is None:
54
self._table.connection.client.mutateRows(self._table.name, bms)
55
self._table.connection.client.mutateRows(self._table.name, bms, {})
56
57
self._table.connection.client.mutateRowsTs(
57
self._table.name, bms, self._timestamp)
58
self._table.name, bms, self._timestamp, {})
59
60
self._reset_mutations()
65
def put(self, row, data):
66
def put(self, row, data, wal=None):
66
67
"""Store data in the table.
68
See :py:meth:`Table.put` for a description of the `row` and `data`
69
See :py:meth:`Table.put` for a description of the `row`, `data`,
70
and `wal` arguments. The `wal` argument should normally not be
71
used; its only use is to override the batch-wide value passed to
72
:py:meth:`Table.batch`.
71
77
self._mutations[row].extend(
72
Mutation(isDelete=False, column=column, value=value)
73
83
for column, value in data.iteritems())
75
85
self._mutation_count += len(data)
76
86
if self._batch_size and self._mutation_count >= self._batch_size:
79
def delete(self, row, columns=None):
89
def delete(self, row, columns=None, wal=None):
80
90
"""Delete data from the table.
82
See :py:meth:`Table.delete` for a description of the `row` and
92
See :py:meth:`Table.put` for a description of the `row`, `data`,
93
and `wal` arguments. The `wal` argument should normally not be
94
used; its only use is to override the batch-wide value passed to
95
:py:meth:`Table.batch`.
85
97
# Work-around Thrift API limitation: the mutation API can only
86
98
# delete specified columns, not complete rows, so just list the
87
# column families once and cache them for later use in the same
99
# column families once and cache them for later use by the same
89
101
if columns is None:
90
102
if self._families is None:
91
103
self._families = self._table._column_family_names()
92
104
columns = self._families
94
109
self._mutations[row].extend(
95
Mutation(isDelete=True, column=column) for column in columns)
110
Mutation(isDelete=True, column=column, writeToWAL=wal)
111
for column in columns)
97
113
self._mutation_count += len(columns)
98
114
if self._batch_size and self._mutation_count >= self._batch_size: