airflow.providers.google.cloud.operators.cloud_sql

This module contains Google Cloud SQL operators.

Module Contents

airflow.providers.google.cloud.operators.cloud_sql.SETTINGS = settings[source]
airflow.providers.google.cloud.operators.cloud_sql.SETTINGS_VERSION = settingsVersion[source]
airflow.providers.google.cloud.operators.cloud_sql.CLOUD_SQL_CREATE_VALIDATION[source]
airflow.providers.google.cloud.operators.cloud_sql.CLOUD_SQL_EXPORT_VALIDATION[source]
airflow.providers.google.cloud.operators.cloud_sql.CLOUD_SQL_IMPORT_VALIDATION[source]
airflow.providers.google.cloud.operators.cloud_sql.CLOUD_SQL_DATABASE_CREATE_VALIDATION[source]
airflow.providers.google.cloud.operators.cloud_sql.CLOUD_SQL_DATABASE_PATCH_VALIDATION[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLBaseOperator(*, instance: str, project_id: Optional[str] = None, gcp_conn_id: str = 'google_cloud_default', api_version: str = 'v1beta4', impersonation_chain: Optional[Union[str, Sequence[str]]] = None, **kwargs)[source]

Bases: airflow.models.BaseOperator

Abstract base operator for Google Cloud SQL operators to inherit from.

Parameters
  • instance (str) -- Cloud SQL instance ID. This does not include the project ID.

  • project_id (str) -- Optional, Google Cloud Project ID. f set to None or missing, the default project_id from the Google Cloud connection is used.

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud.

  • api_version (str) -- API version used (e.g. v1beta4).

  • impersonation_chain (Union[str, Sequence[str]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

execute(self, context)[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLCreateInstanceOperator(*, body: dict, instance: str, project_id: Optional[str] = None, gcp_conn_id: str = 'google_cloud_default', api_version: str = 'v1beta4', validate_body: bool = True, impersonation_chain: Optional[Union[str, Sequence[str]]] = None, **kwargs)[source]

Bases: airflow.providers.google.cloud.operators.cloud_sql.CloudSQLBaseOperator

Creates a new Cloud SQL instance. If an instance with the same name exists, no action will be taken and the operator will succeed.

See also

For more information on how to use this operator, take a look at the guide: CloudSQLCreateInstanceOperator

Parameters
  • body (dict) -- Body required by the Cloud SQL insert API, as described in https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/insert #request-body

  • instance (str) -- Cloud SQL instance ID. This does not include the project ID.

  • project_id (str) -- Optional, Google Cloud Project ID. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud.

  • api_version (str) -- API version used (e.g. v1beta4).

  • validate_body (bool) -- True if body should be validated, False otherwise.

  • impersonation_chain (Union[str, Sequence[str]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

template_fields = ['project_id', 'instance', 'body', 'gcp_conn_id', 'api_version', 'impersonation_chain'][source]
execute(self, context)[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLInstancePatchOperator(*, body: dict, instance: str, project_id: Optional[str] = None, gcp_conn_id: str = 'google_cloud_default', api_version: str = 'v1beta4', impersonation_chain: Optional[Union[str, Sequence[str]]] = None, **kwargs)[source]

Bases: airflow.providers.google.cloud.operators.cloud_sql.CloudSQLBaseOperator

Updates settings of a Cloud SQL instance.

Caution: This is a partial update, so only included values for the settings will be updated.

In the request body, supply the relevant portions of an instance resource, according to the rules of patch semantics. https://cloud.google.com/sql/docs/mysql/admin-api/how-tos/performance#patch

See also

For more information on how to use this operator, take a look at the guide: CloudSQLInstancePatchOperator

Parameters
  • body (dict) -- Body required by the Cloud SQL patch API, as described in https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/patch#request-body

  • instance (str) -- Cloud SQL instance ID. This does not include the project ID.

  • project_id (str) -- Optional, Google Cloud Project ID. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud.

  • api_version (str) -- API version used (e.g. v1beta4).

  • impersonation_chain (Union[str, Sequence[str]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

template_fields = ['project_id', 'instance', 'body', 'gcp_conn_id', 'api_version', 'impersonation_chain'][source]
execute(self, context)[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLDeleteInstanceOperator[source]

Bases: airflow.providers.google.cloud.operators.cloud_sql.CloudSQLBaseOperator

Deletes a Cloud SQL instance.

See also

For more information on how to use this operator, take a look at the guide: CloudSQLDeleteInstanceOperator

Parameters
  • instance (str) -- Cloud SQL instance ID. This does not include the project ID.

  • project_id (str) -- Optional, Google Cloud Project ID. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud.

  • api_version (str) -- API version used (e.g. v1beta4).

  • impersonation_chain (Union[str, Sequence[str]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

template_fields = ['project_id', 'instance', 'gcp_conn_id', 'api_version', 'impersonation_chain'][source]
execute(self, context)[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLCreateInstanceDatabaseOperator(*, instance: str, body: dict, project_id: Optional[str] = None, gcp_conn_id: str = 'google_cloud_default', api_version: str = 'v1beta4', validate_body: bool = True, impersonation_chain: Optional[Union[str, Sequence[str]]] = None, **kwargs)[source]

Bases: airflow.providers.google.cloud.operators.cloud_sql.CloudSQLBaseOperator

Creates a new database inside a Cloud SQL instance.

See also

For more information on how to use this operator, take a look at the guide: CloudSQLCreateInstanceDatabaseOperator

Parameters
  • instance (str) -- Database instance ID. This does not include the project ID.

  • body (dict) -- The request body, as described in https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/databases/insert#request-body

  • project_id (str) -- Optional, Google Cloud Project ID. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud.

  • api_version (str) -- API version used (e.g. v1beta4).

  • validate_body (bool) -- Whether the body should be validated. Defaults to True.

  • impersonation_chain (Union[str, Sequence[str]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

template_fields = ['project_id', 'instance', 'body', 'gcp_conn_id', 'api_version', 'impersonation_chain'][source]
execute(self, context)[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLPatchInstanceDatabaseOperator(*, instance: str, database: str, body: dict, project_id: Optional[str] = None, gcp_conn_id: str = 'google_cloud_default', api_version: str = 'v1beta4', validate_body: bool = True, impersonation_chain: Optional[Union[str, Sequence[str]]] = None, **kwargs)[source]

Bases: airflow.providers.google.cloud.operators.cloud_sql.CloudSQLBaseOperator

Updates a resource containing information about a database inside a Cloud SQL instance using patch semantics. See: https://cloud.google.com/sql/docs/mysql/admin-api/how-tos/performance#patch

See also

For more information on how to use this operator, take a look at the guide: CloudSQLPatchInstanceDatabaseOperator

Parameters
  • instance (str) -- Database instance ID. This does not include the project ID.

  • database (str) -- Name of the database to be updated in the instance.

  • body (dict) -- The request body, as described in https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/databases/patch#request-body

  • project_id (str) -- Optional, Google Cloud Project ID.

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud.

  • api_version (str) -- API version used (e.g. v1beta4).

  • validate_body (bool) -- Whether the body should be validated. Defaults to True.

  • impersonation_chain (Union[str, Sequence[str]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

template_fields = ['project_id', 'instance', 'body', 'database', 'gcp_conn_id', 'api_version', 'impersonation_chain'][source]
execute(self, context)[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLDeleteInstanceDatabaseOperator(*, instance: str, database: str, project_id: Optional[str] = None, gcp_conn_id: str = 'google_cloud_default', api_version: str = 'v1beta4', impersonation_chain: Optional[Union[str, Sequence[str]]] = None, **kwargs)[source]

Bases: airflow.providers.google.cloud.operators.cloud_sql.CloudSQLBaseOperator

Deletes a database from a Cloud SQL instance.

See also

For more information on how to use this operator, take a look at the guide: CloudSQLDeleteInstanceDatabaseOperator

Parameters
  • instance (str) -- Database instance ID. This does not include the project ID.

  • database (str) -- Name of the database to be deleted in the instance.

  • project_id (str) -- Optional, Google Cloud Project ID. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud.

  • api_version (str) -- API version used (e.g. v1beta4).

  • impersonation_chain (Union[str, Sequence[str]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

template_fields = ['project_id', 'instance', 'database', 'gcp_conn_id', 'api_version', 'impersonation_chain'][source]
execute(self, context)[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLExportInstanceOperator(*, instance: str, body: dict, project_id: Optional[str] = None, gcp_conn_id: str = 'google_cloud_default', api_version: str = 'v1beta4', validate_body: bool = True, impersonation_chain: Optional[Union[str, Sequence[str]]] = None, **kwargs)[source]

Bases: airflow.providers.google.cloud.operators.cloud_sql.CloudSQLBaseOperator

Exports data from a Cloud SQL instance to a Cloud Storage bucket as a SQL dump or CSV file.

Note: This operator is idempotent. If executed multiple times with the same export file URI, the export file in GCS will simply be overridden.

See also

For more information on how to use this operator, take a look at the guide: CloudSQLExportInstanceOperator

Parameters
  • instance (str) -- Cloud SQL instance ID. This does not include the project ID.

  • body (dict) -- The request body, as described in https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/export#request-body

  • project_id (str) -- Optional, Google Cloud Project ID. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud.

  • api_version (str) -- API version used (e.g. v1beta4).

  • validate_body (bool) -- Whether the body should be validated. Defaults to True.

  • impersonation_chain (Union[str, Sequence[str]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

template_fields = ['project_id', 'instance', 'body', 'gcp_conn_id', 'api_version', 'impersonation_chain'][source]
execute(self, context)[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLImportInstanceOperator(*, instance: str, body: dict, project_id: Optional[str] = None, gcp_conn_id: str = 'google_cloud_default', api_version: str = 'v1beta4', validate_body: bool = True, impersonation_chain: Optional[Union[str, Sequence[str]]] = None, **kwargs)[source]

Bases: airflow.providers.google.cloud.operators.cloud_sql.CloudSQLBaseOperator

Imports data into a Cloud SQL instance from a SQL dump or CSV file in Cloud Storage.

CSV IMPORT:

This operator is NOT idempotent for a CSV import. If the same file is imported multiple times, the imported data will be duplicated in the database. Moreover, if there are any unique constraints the duplicate import may result in an error.

SQL IMPORT:

This operator is idempotent for a SQL import if it was also exported by Cloud SQL. The exported SQL contains 'DROP TABLE IF EXISTS' statements for all tables to be imported.

If the import file was generated in a different way, idempotence is not guaranteed. It has to be ensured on the SQL file level.

See also

For more information on how to use this operator, take a look at the guide: CloudSqlInstanceImportOperator

Parameters
  • instance (str) -- Cloud SQL instance ID. This does not include the project ID.

  • body (dict) -- The request body, as described in https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/export#request-body

  • project_id (str) -- Optional, Google Cloud Project ID. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud.

  • api_version (str) -- API version used (e.g. v1beta4).

  • validate_body (bool) -- Whether the body should be validated. Defaults to True.

  • impersonation_chain (Union[str, Sequence[str]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated).

template_fields = ['project_id', 'instance', 'body', 'gcp_conn_id', 'api_version', 'impersonation_chain'][source]
execute(self, context)[source]
class airflow.providers.google.cloud.operators.cloud_sql.CloudSQLExecuteQueryOperator(*, sql: Union[List[str], str], autocommit: bool = False, parameters: Optional[Union[Dict, Iterable]] = None, gcp_conn_id: str = 'google_cloud_default', gcp_cloudsql_conn_id: str = 'google_cloud_sql_default', **kwargs)[source]

Bases: airflow.models.BaseOperator

Performs DML or DDL query on an existing Cloud Sql instance. It optionally uses cloud-sql-proxy to establish secure connection with the database.

See also

For more information on how to use this operator, take a look at the guide: CloudSQLExecuteQueryOperator

Parameters
  • sql (str or list[str]) -- SQL query or list of queries to run (should be DML or DDL query - this operator does not return any data from the database, so it is useless to pass it DQL queries. Note that it is responsibility of the author of the queries to make sure that the queries are idempotent. For example you can use CREATE TABLE IF NOT EXISTS to create a table.

  • parameters (dict or iterable) -- (optional) the parameters to render the SQL query with.

  • autocommit (bool) -- if True, each command is automatically committed. (default value: False)

  • gcp_conn_id (str) -- The connection ID used to connect to Google Cloud for cloud-sql-proxy authentication.

  • gcp_cloudsql_conn_id (str) -- The connection ID used to connect to Google Cloud SQL its schema should be gcpcloudsql://. See CloudSQLDatabaseHook for details on how to define gcpcloudsql:// connection.

template_fields = ['sql', 'gcp_cloudsql_conn_id', 'gcp_conn_id'][source]
template_ext = ['.sql'][source]
execute(self, context)[source]

Was this entry helpful?