0

I am not able to import statement as-

from airflow.contrib.operators.gcp_sql_operator import CloudSqlQueryOperator

I want to import this in my DAG file which will be run in cloud composer airflow whose version is 1.10.0 and not 1.9.0.Here just to check, I tried to import gcs_to_gcs as-

from airflow.contrib.operators.gcs_to_gcs import GoogleCloudStorageToGoogleCloudStorageOperator

I am able to import this but not gcp_sql_operator.

Aniruddha Dwivedi
  • 91
  • 1
  • 2
  • 13

1 Answers1

5

The CloudSqlQueryOperator operator is released since Airflow 1.10.2, which is currently not supported in Composer versions. The support for 1.10.2 should be available soon in Composer, before that you may want to manually copy gcp_sql_operator.py and its dependencies to the Composer dags folder following the instruction here.

Feng Lu
  • 691
  • 5
  • 6
  • Hi @Feng, actually I wanted to execute SELECT query which I can't do using cloudsqlqueryoperator. I decided to use cloudsqldatabasehook instead to get connection object and had plans to execute select query by other ways. However in order to use cloudsqldatabasehook, when I try to import it as - from airflow.contrib.hooks.gcp_sql_hook import CloudSqlDatabaseHook I get error "cannot import name CloudSqlDatabaseHook" but I can import cloudsqlhook another class from same gcp_sql_hook.py file. – Aniruddha Dwivedi Apr 10 '19 at 12:43
  • If you look at the gcp_sql_hook.py inside Airflow 1.10.1 (https://github.com/apache/airflow/blob/1.10.1/airflow/contrib/hooks/gcp_sql_hook.py), you'll notice that CloudSqlDatabaseHook class is not included (it is, on the other hand, available in 1.10.2). – Feng Lu Apr 12 '19 at 05:59
  • 1
    Airflow 1.10.2 is now available in Composer. [Here](https://cloud.google.com/composer/docs/concepts/versioning/composer-versions#new_environments) is the list of supported versions. – Tlaquetzal Jul 30 '19 at 19:41