airflow.providers.google.cloud.hooks.spanner
¶
This module contains a Google Cloud Spanner Hook.
Module Contents¶
-
class
airflow.providers.google.cloud.hooks.spanner.
SpannerHook
(gcp_conn_id: str = 'google_cloud_default', delegate_to: Optional[str] = None, impersonation_chain: Optional[Union[str, Sequence[str]]] = None)[source]¶ Bases:
airflow.providers.google.common.hooks.base_google.GoogleBaseHook
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: str)[source]¶ Provides a client for interacting with the Cloud Spanner API.
- Parameters
project_id (str) -- The ID of the Google Cloud project.
- Returns
Client
- Return type
-
get_instance
(self, instance_id: str, project_id: str)[source]¶ Gets information about a particular instance.
- Parameters
- Returns
Spanner instance
- Return type
-
_apply_to_instance
(self, project_id: str, instance_id: str, configuration_name: str, node_count: int, display_name: str, func: Callable[[Instance], Operation])[source]¶ Invokes a method on a given instance by applying a specified Callable.
- Parameters
project_id (str) -- The ID of the Google Cloud 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[google.cloud.spanner_v1.instance.Instance]) -- Method of the instance to be called.
-
create_instance
(self, instance_id: str, configuration_name: str, node_count: int, display_name: str, project_id: str)[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 Google Cloud Console. Must be between 4 and 30 characters. If this value is not passed, the name falls back to the instance ID.
project_id (str) -- Optional, the ID of the Google Cloud project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the Google Cloud connection is used.
- Returns
None
-
update_instance
(self, instance_id: str, configuration_name: str, node_count: int, display_name: str, project_id: str)[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 Google Cloud 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 Google Cloud project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the Google Cloud connection is used.
- Returns
None
-
delete_instance
(self, instance_id: str, project_id: str)[source]¶ Deletes an existing Cloud Spanner instance.
-
get_database
(self, instance_id: str, database_id: str, project_id: str)[source]¶ Retrieves a database in Cloud Spanner. If the database does not exist in the specified instance, it returns None.
- Parameters
instance_id (str) -- The ID of the Cloud Spanner instance.
database_id (str) -- The ID of the database in Cloud Spanner.
project_id (str) -- Optional, the ID of the Google Cloud project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the Google Cloud connection is used.
- Returns
Database object or None if database does not exist
- Return type
-
create_database
(self, instance_id: str, database_id: str, ddl_statements: List[str], project_id: str)[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 Google Cloud project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the Google Cloud connection is used.
- Returns
None
-
update_database
(self, instance_id: str, database_id: str, ddl_statements: List[str], project_id: str, operation_id: Optional[str] = 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 Google Cloud project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the Google Cloud 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: str, database_id, project_id: str)[source]¶ Drops 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.
project_id (str) -- Optional, the ID of the Google Cloud project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the Google Cloud connection is used.
- Returns
True if everything succeeded
- Return type
-
execute_dml
(self, instance_id: str, database_id: str, queries: List[str], project_id: str)[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 (List[str]) -- The queries to execute.
project_id (str) -- Optional, the ID of the Google Cloud project that owns the Cloud Spanner database. If set to None or missing, the default project_id from the Google Cloud connection is used.
-