from airflow import DAG from airflow.operators.python_operator import PythonOperator from airflow.hooks.mssql_hook import MsSqlHook
def query_mssql(): mssql_hook = MsSqlHook(mssql_conn_id='my_mssql_conn') connection = mssql_hook.get_conn() cursor = connection.cursor() cursor.execute("SELECT * FROM my_table") results = cursor.fetchall() print(results)
dag = DAG('mssql_dag', description='MSSQL query DAG') run_this = PythonOperator( task_id='query_mssql_task', python_callable=query_mssql, dag=dag)