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_instance(self, instance_id: str, project_id: str)[source]

Gets information about a particular instance.

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

  • instance_id (str) -- The ID of the Cloud Spanner instance.

Returns

Spanner instance

Return type

google.cloud.spanner_v1.instance.Instance

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.

Parameters
  • instance_id (str) -- The ID of the Cloud Spanner instance.

  • 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

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

google.cloud.spanner_v1.database.Database or None

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

bool

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.

Was this entry helpful?