HappyBase Batch#
Google Cloud Bigtable HappyBase batch module.
-
class
google.cloud.happybase.batch.
Batch
(table, timestamp=None, batch_size=None, transaction=False, wal=<object object>)[source]# Bases:
object
Batch class for accumulating mutations.
Note
When using a batch with
transaction=False
as a context manager (i.e. in awith
statement), mutations will still be sent as row mutations even if the context manager exits with an error. This behavior is in place to match the behavior in the HappyBase HBase / Thrift implementation.Parameters: - table (
Table
) – The table where mutations will be applied. - timestamp (int) – (Optional) Timestamp (in milliseconds since the epoch) that all mutations will be applied at.
- batch_size (int) – (Optional) The maximum number of mutations to allow to accumulate before committing them.
- transaction (bool) – Flag indicating if the mutations should be sent
transactionally or not. If
transaction=True
and an error occurs while aBatch
is active, then none of the accumulated mutations will be committed. Ifbatch_size
is set, the mutation can’t be transactional. - wal (object) – Unused parameter (Boolean for using the HBase Write Ahead Log). Provided for compatibility with HappyBase, but irrelevant for Cloud Bigtable since it does not have a Write Ahead Log.
Raises: TypeError
ifbatch_size
is set andtransaction=True
.ValueError
ifbatch_size
is not positive.-
delete
(row, columns=None, wal=<object object>)[source]# Delete data from a row in the table owned by this batch.
Parameters: - row (str) – The row key where the delete will occur.
- columns (list) –
(Optional) Iterable containing column names (as strings). Each column name can be either
- an entire column family:
fam
orfam:
- a single column:
fam:col
If not used, will delete the entire row.
- an entire column family:
- wal (object) – Unused parameter (to over-ride the default on the instance). Provided for compatibility with HappyBase, but irrelevant for Cloud Bigtable since it does not have a Write Ahead Log.
Raises: If the delete timestamp range is set on the current batch, but a full row delete is attempted.
-
put
(row, data, wal=<object object>)[source]# Insert data into a row in the table owned by this batch.
Parameters: - row (str) – The row key where the mutation will be “put”.
- data (dict) – Dictionary containing the data to be inserted. The keys
are columns names (of the form
fam:col
) and the values are strings (bytes) to be stored in those columns. - wal (object) – Unused parameter (to over-ride the default on the instance). Provided for compatibility with HappyBase, but irrelevant for Cloud Bigtable since it does not have a Write Ahead Log.
- table (