Class Table (2.3.3)

Table(table_id, instance, mutation_timeout=None, app_profile_id=None)

Representation of a Google Cloud Bigtable Table.

  • create the table
  • delete the table
  • list_column_families in the table

Parameters

NameDescription
table_id str

The ID of the table.

instance Instance

The instance that owns the table.

app_profile_id str

(Optional) The unique name of the AppProfile.

Properties

name

Table name used in requests.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_table_name] :end-before: [END bigtable_api_table_name] :dedent: 4

"projects/../instances/../tables/{table_id}"

Returns
TypeDescription
strThe table name.

Methods

append_row

append_row(row_key)

Create a xref_AppendRow associated with this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_table_append_row] :end-before: [END bigtable_api_table_append_row] :dedent: 4

Parameter
NameDescription
row_key bytes

The key for the row being created.

backup

backup(backup_id, cluster_id=None, expire_time=None)

Factory to create a Backup linked to this Table.

Parameters
NameDescription
backup_id str

The ID of the Backup to be created.

cluster_id str

(Optional) The ID of the Cluster. Required for calling 'delete', 'exists' etc. methods.

expire_time datetime.datetime

(Optional) The expiration time of this new Backup. Required, if the create method needs to be called.

Returns
TypeDescription
.BackupA backup linked to this table.

column_family

column_family(column_family_id, gc_rule=None)

Factory to create a column family associated with this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_table_column_family] :end-before: [END bigtable_api_table_column_family] :dedent: 4

Parameters
NameDescription
column_family_id str

The ID of the column family. Must be of the form <code>_a-zA-Z0-9][-_.a-zA-Z0-9]</code>*.

gc_rule .GarbageCollectionRule

(Optional) The garbage collection settings for this column family.

Returns
TypeDescription
.ColumnFamilyA column family owned by this table.

conditional_row

conditional_row(row_key, filter_)

Create a xref_ConditionalRow associated with this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_table_conditional_row] :end-before: [END bigtable_api_table_conditional_row] :dedent: 4

Parameters
NameDescription
row_key bytes

The key for the row being created.

filter_ .RowFilter

(Optional) Filter to be used for conditional mutations. See .ConditionalRow for more details.

create

create(initial_split_keys=[], column_families={})

Creates this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_create_table] :end-before: [END bigtable_api_create_table] :dedent: 4

Parameters
NameDescription
initial_split_keys list

(Optional) list of row keys in bytes that will be used to initially split the table into several tablets.

column_families dict

(Optional) A map columns to create. The key is the column_id str and the value is a GarbageCollectionRule

delete

delete()

Delete this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_delete_table] :end-before: [END bigtable_api_delete_table] :dedent: 4

direct_row

direct_row(row_key)

Create a xref_DirectRow associated with this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_table_direct_row] :end-before: [END bigtable_api_table_direct_row] :dedent: 4

Parameter
NameDescription
row_key bytes

The key for the row being created.

drop_by_prefix

drop_by_prefix(row_key_prefix, timeout=None)

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_drop_by_prefix] :end-before: [END bigtable_api_drop_by_prefix] :dedent: 4

Parameters
NameDescription
row_key_prefix bytes

Delete all rows that start with this row key prefix. Prefix cannot be zero length.

timeout float

(Optional) The amount of time, in seconds, to wait for the request to complete. :raise: google.api_core.exceptions.GoogleAPICallError: If the request failed for any reason. google.api_core.exceptions.RetryError: If the request failed due to a retryable error and retry attempts failed. ValueError: If the parameters are invalid.

exists

exists()

Check whether the table exists.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_check_table_exists] :end-before: [END bigtable_api_check_table_exists] :dedent: 4

Returns
TypeDescription
boolTrue if the table exists, else False.

get_cluster_states

get_cluster_states()

List the cluster states owned by this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_get_cluster_states] :end-before: [END bigtable_api_get_cluster_states] :dedent: 4

Returns
TypeDescription
dictDictionary of cluster states for this table. Keys are cluster ids and values are :class: 'ClusterState' instances.

get_encryption_info

get_encryption_info()

List the encryption info for each cluster owned by this table.

Gets the current encryption info for the table across all of the clusters. The returned dict will be keyed by cluster id and contain a status for all of the keys in use.

Returns
TypeDescription
dictDictionary of encryption info for this table. Keys are cluster ids and values are tuples of EncryptionInfo instances.

get_iam_policy

get_iam_policy()

Gets the IAM access control policy for this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_table_get_iam_policy] :end-before: [END bigtable_api_table_get_iam_policy] :dedent: 4

Returns
TypeDescription
PolicyThe current IAM policy of this table.

list_backups

list_backups(cluster_id=None, filter_=None, order_by=None, page_size=0)

List Backups for this Table.

Parameters
NameDescription
cluster_id str

(Optional) Specifies a single cluster to list Backups from. If none is specified, the returned list contains all the Backups in this Instance.

filter_ str

(Optional) A filter expression that filters backups listed in the response. The expression must specify the field name, a comparison operator, and the value that you want to use for filtering. The value must be a string, a number, or a boolean. The comparison operator must be <, >, <=, >=, !=, =, or :. Colon ':' represents a HAS operator which is roughly synonymous with equality. Filter rules are case insensitive. The fields eligible for filtering are: - name - source_table - state - start_time (values of the format YYYY-MM-DDTHH:MM:SSZ) - end_time (values of the format YYYY-MM-DDTHH:MM:SSZ) - expire_time (values of the format YYYY-MM-DDTHH:MM:SSZ) - size_bytes To filter on multiple expressions, provide each separate expression within parentheses. By default, each expression is an AND expression. However, you can include AND, OR, and NOT expressions explicitly. Some examples of using filters are: - name:"exact" --> The Backup name is the string "exact". - name:howl --> The Backup name contains the string "howl" - source_table:prod --> The source table's name contains the string "prod". - state:CREATING --> The Backup is pending creation. - state:READY --> The Backup is created and ready for use. - (name:howl) AND (start_time < "2020-05-28T14:50:00Z") --> The Backup name contains the string "howl" and the Backup start time is before 2020-05-28T14:50:00Z. - size_bytes > 10000000000 --> The Backup size is greater than 10GB

order_by str

(Optional) An expression for specifying the sort order of the results of the request. The string value should specify one or more fields in Backup. The full syntax is described at https://aip.dev/132#ordering. Fields supported are: * name * source_table * expire_time * start_time * end_time * size_bytes * state For example, "start_time". The default sorting order is ascending. To specify descending order for the field, a suffix " desc" should be appended to the field name. For example, "start_time desc". Redundant space characters in the syntax are insigificant. If order_by is empty, results will be sorted by start_time in descending order starting from the most recently created backup.

page_size int

(Optional) The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

Exceptions
TypeDescription
`ValueErro
Returns
TypeDescription
google.api_core.page_iterator.IteratorIterator of Backup resources within the current Instance.

list_column_families

list_column_families()

List the column families owned by this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_list_column_families] :end-before: [END bigtable_api_list_column_families] :dedent: 4

Exceptions
TypeDescription
`ValueErro
Returns
TypeDescription
dictDictionary of column families attached to this table. Keys are strings (column family names) and values are .ColumnFamily instances.

mutate_rows

mutate_rows(rows, retry=<google.api_core.retry.Retry object>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>)

Mutates multiple rows in bulk.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_mutate_rows] :end-before: [END bigtable_api_mutate_rows] :dedent: 4

The method tries to update all specified rows. If some of the rows weren't updated, it would not remove mutations. They can be applied to the row separately. If row mutations finished successfully, they would be cleaned up.

Optionally, a retry strategy can be specified to re-attempt mutations on rows that return transient errors. This method will retry until all rows succeed or until the request deadline is reached. To specify a retry strategy of "do-nothing", a deadline of 0.0 can be specified.

Parameters
NameDescription
rows list

List or other iterable of .DirectRow instances.

retry google.api_core.retry.Retry

(Optional) Retry delay and deadline arguments. To override, the default value DEFAULT_RETRY can be used and modified with the google.api_core.retry.Retry.with_delay method or the google.api_core.retry.Retry.with_deadline method.

timeout float

number of seconds bounding retries for the call

Returns
TypeDescription
listA list of response statuses (google.rpc.status_pb2.Status) corresponding to success or failure of each row mutation sent. These will be in the same order as the rows.

mutations_batcher

mutations_batcher(flush_count=1000, max_row_bytes=5242880)

Factory to create a mutation batcher associated with this instance.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_mutations_batcher] :end-before: [END bigtable_api_mutations_batcher] :dedent: 4

Parameters
NameDescription
flush_count int

(Optional) Maximum number of rows per batch. If it reaches the max number of rows it calls finish_batch() to mutate the current row batch. Default is FLUSH_COUNT (1000 rows).

max_row_bytes int

(Optional) Max number of row mutations size to flush. If it reaches the max number of row mutations size it calls finish_batch() to mutate the current row batch. Default is MAX_ROW_BYTES (5 MB).

read_row

read_row(row_key, filter_=None)

Read a single row from this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_read_row] :end-before: [END bigtable_api_read_row] :dedent: 4

Parameters
NameDescription
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.

Exceptions
TypeDescription
`ValueErro
Returns
TypeDescription
.PartialRowData, :data:NoneType The contents of the row if any chunks were returned in the response, otherwise :data:None.

read_rows

read_rows(start_key=None, end_key=None, limit=None, filter_=None, end_inclusive=False, row_set=None, retry=<google.api_core.retry.Retry object>)

Read rows from this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_read_rows] :end-before: [END bigtable_api_read_rows] :dedent: 4

Parameters
NameDescription
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.

end_inclusive bool

(Optional) Whether the end_key should be considered inclusive. The default is False (exclusive).

row_set .RowSet

(Optional) The row set containing multiple row keys and row_ranges.

retry google.api_core.retry.Retry

(Optional) Retry delay and deadline arguments. To override, the default value DEFAULT_RETRY_READ_ROWS can be used and modified with the google.api_core.retry.Retry.with_delay method or the google.api_core.retry.Retry.with_deadline method.

Returns
TypeDescription
.PartialRowsDataA .PartialRowsData a generator for consuming the streamed results.

restore

restore(new_table_id, cluster_id=None, backup_id=None, backup_name=None)

Creates a new Table by restoring from the Backup specified by either backup_id or backup_name. The returned long-running operation can be used to track the progress of the operation and to cancel it. The response type is Table, if successful.

Parameters
NameDescription
new_table_id str

The ID of the Table to create and restore to. This Table must not already exist.

cluster_id str

The ID of the Cluster containing the Backup. This parameter gets overriden by backup_name, if the latter is provided.

backup_id str

The ID of the Backup to restore the Table from. This parameter gets overriden by backup_name, if the latter is provided.

backup_name str

(Optional) The full name of the Backup to restore from. If specified, it overrides the cluster_id and backup_id parameters even of such specified. :return: An instance of _OperationFuture.

Exceptions
TypeDescription
google.api_core.exceptions.AlreadyExistsIf the table already exists.
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

row

row(row_key, filter_=None, append=False)

Factory to create a row associated with this table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_table_row] :end-before: [END bigtable_api_table_row] :dedent: 4

Parameters
NameDescription
row_key bytes

The key for the row being created.

filter_ .RowFilter

(Optional) Filter to be used for conditional mutations. See .ConditionalRow for more details.

append bool

(Optional) Flag to determine if the row should be used for append mutations.

Exceptions
TypeDescription
`ValueErro
Returns
TypeDescription
RowA row owned by this table.

sample_row_keys

sample_row_keys()

Read a sample of row keys in the table.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_sample_row_keys] :end-before: [END bigtable_api_sample_row_keys] :dedent: 4

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 and row_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.

Returns
TypeDescription
GrpcRendezvousA cancel-able iterator. Can be consumed by calling next() or by casting to a list and can be cancelled by calling cancel().

set_iam_policy

set_iam_policy(policy)

Sets the IAM access control policy for this table. Replaces any existing policy.

For more information about policy, please see documentation of class google.cloud.bigtable.policy.Policy

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_table_set_iam_policy] :end-before: [END bigtable_api_table_set_iam_policy] :dedent: 4

Parameter
NameDescription
policy Policy

A new IAM policy to replace the current IAM policy of this table.

Returns
TypeDescription
PolicyThe current IAM policy of this table.

test_iam_permissions

test_iam_permissions(permissions)

Tests whether the caller has the given permissions for this table. Returns the permissions that the caller has.

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_table_test_iam_permissions] :end-before: [END bigtable_api_table_test_iam_permissions] :dedent: 4

Parameter
NameDescription
permissions list

The set of permissions to check for the resource. Permissions with wildcards (such as '' or 'storage.') are not allowed. For more information see IAM Overview https://cloud.google.com/iam/docs/overview#permissions. Bigtable Permissions https://cloud.google.com/bigtable/docs/access-control.

Returns
TypeDescription
listA List(string) of permissions allowed on the table.

truncate

truncate(timeout=None)

Truncate the table

For example:

.. literalinclude:: snippets_table.py :start-after: [START bigtable_api_truncate_table] :end-before: [END bigtable_api_truncate_table] :dedent: 4

Parameter
NameDescription
timeout float

(Optional) The amount of time, in seconds, to wait for the request to complete. :raise: google.api_core.exceptions.GoogleAPICallError: If the request failed for any reason. google.api_core.exceptions.RetryError: If the request failed due to a retryable error and retry attempts failed. ValueError: If the parameters are invalid.

yield_rows

yield_rows(**kwargs)

Read rows from this table.

Parameters
NameDescription
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.

row_set .RowSet

(Optional) The row set containing multiple row keys and row_ranges.

Returns
TypeDescription
.PartialRowDataA .PartialRowData for each row returned