MssqlHook气流连接 [英] MssqlHook airflow connection

查看:98
本文介绍了MssqlHook气流连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用气流是陌生的,我需要做的是使用MssqlHook,但我不知道如何。我应该在构造函数中提供哪些元素?

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?

我在气流中的连接名为connection_test。

I have a connection in airflow with name connection_test.

I不完全了解该类中的属性:

I do not fully understand the attributes in the class:

class MsSqlHook(DbApiHook):
    """
    Interact with Microsoft SQL Server.
    """

    conn_name_attr = 'mssql_conn_id'
    default_conn_name = 'mssql_default'
    supports_autocommit = True

我有以下代码:

sqlhook=MsSqlHook(connection_test)
sqlhook.get_conn()

当我这样做时此错误是由于未知原因连接失败

And when I do this the error is Connection failed for unknown reason.

我应该怎么做才能使其与气流连接一起工作?

How should I do in order to make it work with the airflow connection ?

我需要为MsSqlHook调用函数.get_conn()。

What I need is to call function .get_conn() for the MsSqlHook.

推荐答案

请参阅气流的标准示例。

See the standard examples of Airflow.

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

例如:

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

编辑

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

您需要提供在连接中定义的连接。同样,如果使用挂钩,在各个操作符中查找通常会产生一些有关用法的信息。这段代码来自MSSQLOperator。

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.

这篇关于MssqlHook气流连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆