Table#
User friendly container for Google Cloud Bigtable Table.
-
class
google.cloud.bigtable.table.
Table
(table_id, instance)[source]# Bases:
object
Representation of a Google Cloud Bigtable Table.
Note
We don’t define any properties on a table other than the name. The only other fields are
column_families
andgranularity
, Thecolumn_families
are not stored locally andgranularity
is an enum with only one value.We can use a
Table
to: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, column_families=())[source]# Creates this table.
Note
A create request returns a
_generated.table_pb2.Table
but we don’t use this response.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, )
. - column_families (list) – (Optional) List or other iterable of
ColumnFamily
instances.
- 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,
-
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 ColumnFamily
instances.Raises: ValueError
if 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_id
does not, but the return value is not cached.The table name is of the form
"projects/../instances/../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: ValueError
if 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
PartialRowsData
convenience 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_
andappend
can be used in aRow
.Parameters: Return type: Returns: A row owned by this table.
Raises: ValueError
if bothfilter_
andappend
are 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_bytes
androw_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_bytes
field 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_bytes
fields.Return type: GrpcRendezvous
Returns: A cancel-able iterator. Can be consumed by calling next()
or by casting to alist
and can be cancelled by callingcancel()
.