airflow.providers.google.cloud.hooks.spanner
¶
This module contains a Google Cloud Spanner Hook.
Module Contents¶
Classes¶
Information about Google Spanner connection parameters. |
|
Hook for Google Cloud Spanner APIs. |
- class airflow.providers.google.cloud.hooks.spanner.SpannerConnectionParams[source]¶
Bases:
NamedTuple
Information about Google Spanner connection parameters.
- class airflow.providers.google.cloud.hooks.spanner.SpannerHook(gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]¶
Bases:
airflow.providers.google.common.hooks.base_google.GoogleBaseHook
,airflow.providers.common.sql.hooks.sql.DbApiHook
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_sqlalchemy_engine(engine_kwargs=None)[source]¶
Get an sqlalchemy_engine object.
- Parameters
engine_kwargs – Kwargs used in
create_engine()
.- Returns
the created engine.
- get_instance(instance_id, project_id)[source]¶
Gets information about a particular instance.
- Parameters
- Returns
Spanner instance
- Return type
- create_instance(instance_id, configuration_name, node_count, display_name, project_id)[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
- Return type
None
- update_instance(instance_id, configuration_name, node_count, display_name, project_id)[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
- Return type
None
- get_database(instance_id, database_id, project_id)[source]¶
Retrieves a database in Cloud Spanner; return None if the database does not exist in the instance.
- 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(instance_id, database_id, ddl_statements, project_id)[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
- Return type
None
- update_database(instance_id, database_id, ddl_statements, project_id, 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 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 | None) – (Optional) The unique per database operation ID that can be specified to implement idempotency check.
- Returns
None
- Return type
None
- delete_database(instance_id, database_id, project_id)[source]¶
Drops a database in Cloud Spanner.
- Parameters
instance_id (str) – The ID of the Cloud Spanner instance.
database_id – 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(instance_id, database_id, queries, project_id)[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.
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.