Table#
Warning
gRPC is required for using the Cloud Bigtable API. As of May 2016,
grpcio is only supported in Python 2.7, so importing
gcloud.bigtable in other versions of Python will fail.
User friendly container for Google Cloud Bigtable Table.
-
class
gcloud.bigtable.table.Table(table_id, instance)[source]# Bases:
objectRepresentation of a Google Cloud Bigtable Table.
Note
We don’t define any properties on a table other than the name. As the proto says, in a request:
Thenamefield of the Table and all of its ColumnFamilies must be left blank, and will be populated in the response.This leaves only the
current_operationandgranularityfields. Thecurrent_operationis only used for responses whilegranularityis an enum with only one value.We can use a
Tableto:create()the tablerename()the tabledelete()the tablelist_column_families()in the table
Parameters: -
column_family(column_family_id, gc_rule=None)[source]# Factory to create a column family associated with this table.
Parameters: - column_family_id (str) – The ID of the column family. Must be of the
form
[_a-zA-Z0-9][-_.a-zA-Z0-9]*. - gc_rule (
GarbageCollectionRule) – (Optional) The garbage collection settings for this column family.
Return type: Returns: A column family owned by this table.
- column_family_id (str) – The ID of the column family. Must be of the
form
-
create(initial_split_keys=None)[source]# Creates this table.
Note
Though a
_generated_v2.table_pb2.Tableis also allowed (as thetableproperty) in a create table request, we do not support it in this method. As mentioned in theTabledocstring, the name is the only useful property in the table proto.Note
A create request returns a
_generated_v2.table_pb2.Tablebut we don’t use this response. The proto definition allows for the inclusion of acurrent_operationin the response, but it does not appear that the Cloud Bigtable API returns any operation.Parameters: initial_split_keys (list) – (Optional) List of row keys that will be used to initially split the table into several tablets (Tablets are similar to HBase regions). Given two split keys, "s1"and"s2", three tablets will be created, spanning the key ranges:[, s1),[s1, s2),[s2, ).
-
list_column_families()[source]# List the column families owned by this table.
Return type: dict Returns: Dictionary of column families attached to this table. Keys are strings (column family names) and values are ColumnFamilyinstances.Raises: ValueErrorif the column family name from the response does not agree with the computed name from the column family ID.
-
name# Table name used in requests.
Note
This property will not change if
table_iddoes not, but the return value is not cached.The table name is of the form
"projects/../zones/../clusters/../tables/{table_id}"Return type: str Returns: The table name.
-
read_row(row_key, filter_=None)[source]# Read a single row from this table.
Parameters: - row_key (bytes) – The key of the row to read from.
- filter (
RowFilter) – (Optional) The filter to apply to the contents of the row. If unset, returns the entire row.
Return type: Returns: The contents of the row if any chunks were returned in the response, otherwise
None.Raises: ValueErrorif a commit row chunk is never encountered.
-
read_rows(start_key=None, end_key=None, limit=None, filter_=None)[source]# Read rows from this table.
Parameters: - start_key (bytes) – (Optional) The beginning of a range of row keys to
read from. The range will include
start_key. If left empty, will be interpreted as the empty string. - end_key (bytes) – (Optional) The end of a range of row keys to read from.
The range will not include
end_key. If left empty, will be interpreted as an infinite string. - limit (int) – (Optional) The read will terminate after committing to N rows’ worth of results. The default (zero) is to return all results.
- filter (
RowFilter) – (Optional) The filter to apply to the contents of the specified row(s). If unset, reads every column in each row.
Return type: Returns: A
PartialRowsDataconvenience wrapper for consuming the streamed results.- start_key (bytes) – (Optional) The beginning of a range of row keys to
read from. The range will include
-
row(row_key, filter_=None, append=False)[source]# Factory to create a row associated with this table.
Warning
At most one of
filter_andappendcan be used in aRow.Parameters: Return type: Returns: A row owned by this table.
Raises: ValueErrorif bothfilter_andappendare used.
-
sample_row_keys()[source]# Read a sample of row keys in the table.
The returned row keys will delimit contiguous sections of the table of approximately equal size, which can be used to break up the data for distributed tasks like mapreduces.
The elements in the iterator are a SampleRowKeys response and they have the properties
offset_bytesandrow_key. They occur in sorted order. The table might have contents before the first row key in the list and after the last one, but a key containing the empty string indicates “end of table” and will be the last response given, if present.Note
Row keys in this list may not have ever been written to or read from, and users should therefore not make any assumptions about the row key structure that are specific to their use case.
The
offset_bytesfield on a response indicates the approximate total storage space used by all rows in the table which precederow_key. Buffering the contents of all rows between two subsequent samples would require space roughly equal to the difference in theiroffset_bytesfields.Return type: grpc.framework.alpha._reexport._CancellableIteratorReturns: A cancel-able iterator. Can be consumed by calling next()or by casting to alistand can be cancelled by callingcancel().