MssqlHook airflow connection

后端 未结 1 1975
南旧
南旧 2021-01-22 17:20

I am new to using airflow and what I need to do is to use MssqlHook but I do not know how. What elements should I give in the constructor?

I have a connection in airflow

1条回答
  •  情歌与酒
    2021-01-22 18:04

    See the standard examples of Airflow.

    https://github.com/gtoonstra/etl-with-airflow/blob/master/examples/mssql-example/dags/mssql_bcp_example.py

    E.g.:

    t1 = MsSqlImportOperator(task_id='import_data',
                             table_name='test.test',
                             generate_synth_data=generate_synth_data,
                             mssql_conn_id='mssql',
                             dag=dag)
    

    EDIT

    hook = MsSqlHook(mssql_conn_id="my_mssql_conn")
    hook.run(sql)
    

    You need to provide the connection defined in Connections. Also if using Hooks looking in the respective Operators usually yields some information about usage. This code is from the MSSQLOperator.

    0 讨论(0)
提交回复
热议问题