Use the BigQueryOperator

Use the BigQueryOperator in an Apache Airflow DAG to run a BigQuery query from Cloud Composer.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample

Python

from airflow.contrib.operators import bigquery_operator
    # Query recent StackOverflow questions.
    bq_recent_questions_query = bigquery_operator.BigQueryOperator(
        task_id='bq_recent_questions_query',
        sql="""
        SELECT owner_display_name, title, view_count
        FROM `bigquery-public-data.stackoverflow.posts_questions`
        WHERE creation_date < CAST('{max_date}' AS TIMESTAMP)
            AND creation_date >= CAST('{min_date}' AS TIMESTAMP)
        ORDER BY view_count DESC
        LIMIT 100
        """.format(max_date=max_query_date, min_date=min_query_date),
        use_legacy_sql=False,
        destination_dataset_table=bq_recent_questions_table_id)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser