Created
February 28, 2022 08:55
-
-
Save takat0-h0rikosh1/6852b842aa3adfcdae37df06295cce04 to your computer and use it in GitHub Desktop.
example_airflow_bq_hook_insert_all_dag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from airflow.operators.python_operator import PythonOperator | |
from airflow.utils.dates import days_ago | |
from airflow import DAG | |
from airflow.providers.google.cloud.hooks.bigquery import BigQueryHook | |
default_args = { | |
'owner': 'airflow', | |
'depends_on_past': False, | |
'start_date': days_ago(2), | |
'retries': 0, | |
} | |
with DAG( | |
'bq_hook_insert_all_test', | |
default_args=default_args, | |
description='bq_hook_insert_all_test', | |
catchup=False, | |
max_active_runs=1, | |
concurrency=3, | |
) as dag: | |
def bq_hook_insert_all_test(): | |
bq_hook = BigQueryHook(use_legacy_sql=False) | |
bq_hook.insert_all( | |
project_id=bq_hook.project_id, | |
dataset_id="temp_horikoshi", | |
table_id="bq_hook_insert_all_test", | |
rows=[{"name": "岩崎弥太郎"}], | |
fail_on_error=True, | |
) | |
test = PythonOperator( | |
task_id=f'bq_hook_insert_all_test', | |
python_callable=bq_hook_insert_all_test, | |
provide_context=True, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment