airflow.contrib.hooks.gcp_spanner_hook
¶
Module Contents¶
-
class
airflow.contrib.hooks.gcp_spanner_hook.
CloudSpannerHook
(gcp_conn_id='google_cloud_default', delegate_to=None)[source]¶ Bases:
airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook
Hook for Google Cloud Spanner APIs.
All the methods in the hook where project_id is used must be called with keyword arguments rather than positional.
-
_get_client
(self, project_id)[source]¶ Provides a client for interacting with the Cloud Spanner API.
-
get_instance
(self, instance_id, project_id=None)[source]¶ Gets information about a particular instance.
- Parameters
- Returns
google.cloud.spanner_v1.instance.Instance
- Return type
-
_apply_to_instance
(self, project_id, instance_id, configuration_name, node_count, display_name, func)[source]¶ Invokes a method on a given instance by applying a specified Callable.
- Parameters
project_id (str) – The ID of the GCP project that owns the Cloud Spanner database.
instance_id (str) – The ID of the instance.
configuration_name (str) – Name of the instance configuration defining how the instance will be created. Required for instances which do not yet exist.
node_count (int) – (Optional) Number of nodes allocated to the instance.
display_name (str) – (Optional) The display name for the instance in the Cloud Console UI. (Must be between 4 and 30 characters.) If this value is not set in the constructor, will fall back to the instance ID.
func (Callable) – Method of the instance to be called.
-
create_instance
(self, instance_id, configuration_name, node_count, display_name, project_id=None)[source]¶ Creates a new Cloud Spanner instance.
- Parameters
instance_id (str) – The ID of the Cloud Spanner instance.
configuration_name (str) – The name of the instance configuration defining how the instance will be created. Possible configuration values can be retrieved via https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instanceConfigs/list
node_count (int) – (Optional) The number of nodes allocated to the Cloud Spanner instance.
display_name (str) – (Optional) The display name for the instance in the GCP Console. Must be between 4 and 30 characters. If this value is not set in the constructor, the name falls back to the instance ID.
project_id (str) – Optional, the ID of the GCP project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the GCP connection is used.
- Returns
None
-
update_instance
(self, instance_id, configuration_name, node_count, display_name, project_id=None)[source]¶ Updates an existing Cloud Spanner instance.
- Parameters
instance_id (str) – The ID of the Cloud Spanner instance.
configuration_name (str) – The name of the instance configuration defining how the instance will be created. Possible configuration values can be retrieved via https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instanceConfigs/list
node_count (int) – (Optional) The number of nodes allocated to the Cloud Spanner instance.
display_name (str) – (Optional) The display name for the instance in the GCP Console. Must be between 4 and 30 characters. If this value is not set in the constructor, the name falls back to the instance ID.
project_id (str) – Optional, the ID of the GCP project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the GCP connection is used.
- Returns
None
-
delete_instance
(self, instance_id, project_id=None)[source]¶ Deletes an existing Cloud Spanner instance.
-
get_database
(self, instance_id, database_id, project_id=None)[source]¶ Retrieves a database in Cloud Spanner. If the database does not exist in the specified instance, it returns None.
- Parameters
- Returns
Database object or None if database does not exist
- Return type
-
create_database
(self, instance_id, database_id, ddl_statements, project_id=None)[source]¶ Creates a new database in Cloud Spanner.
- Parameters
instance_id (str) – The ID of the Cloud Spanner instance.
database_id (str) – The ID of the database to create in Cloud Spanner.
ddl_statements (list[str]) – The string list containing DDL for the new database.
project_id (str) – Optional, the ID of the GCP project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the GCP connection is used.
- Returns
None
-
update_database
(self, instance_id, database_id, ddl_statements, project_id=None, operation_id=None)[source]¶ Updates DDL of a database in Cloud Spanner.
- Parameters
instance_id (str) – The ID of the Cloud Spanner instance.
database_id (str) – The ID of the database in Cloud Spanner.
ddl_statements (list[str]) – The string list containing DDL for the new database.
project_id (str) – Optional, the ID of the GCP project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the GCP connection is used.
operation_id (str) – (Optional) The unique per database operation ID that can be specified to implement idempotency check.
- Returns
None
-
delete_database
(self, instance_id, database_id, project_id=None)[source]¶ Drops a database in Cloud Spanner.
- Parameters
- Returns
True if everything succeeded
- Return type
-
execute_dml
(self, instance_id, database_id, queries, project_id=None)[source]¶ Executes an arbitrary DML query (INSERT, UPDATE, DELETE).
- Parameters
instance_id (str) – The ID of the Cloud Spanner instance.
database_id (str) – The ID of the database in Cloud Spanner.
queries (str) – The queries to execute.
project_id (str) – Optional, the ID of the GCP project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the GCP connection is used.
-