airflow.providers.trino.hooks.trino

属性

T

异常

TrinoException

Trino 异常。

TrinoHook

通过 trino 包与 Trino 交互。

函数

generate_trino_client_info()

返回包含 dag_id、task_id、logical_date 和 try_number 的 JSON 字符串。

模块内容

airflow.providers.trino.hooks.trino.T[source]
airflow.providers.trino.hooks.trino.generate_trino_client_info()[source]

返回包含 dag_id、task_id、logical_date 和 try_number 的 JSON 字符串。

exception airflow.providers.trino.hooks.trino.TrinoException[source]

基类: Exception

Trino 异常。

class airflow.providers.trino.hooks.trino.TrinoHook(*args, **kwargs)[source]

基类: airflow.providers.common.sql.hooks.sql.DbApiHook

通过 trino 包与 Trino 交互。

>>> ph = TrinoHook()
>>> sql = "SELECT count(1) AS num FROM airflow.static_babynames"
>>> ph.get_records(sql)
[[340698]]
conn_name_attr = 'trino_conn_id'[source]
default_conn_name = 'trino_default'[source]
conn_type = 'trino'[source]
hook_name = 'Trino'[source]
strip_semicolon = True[source]
query_id = ''[source]
classmethod get_ui_field_behaviour()[source]

返回自定义字段行为。

get_conn()[source]

返回一个连接对象。

get_isolation_level()[source]

返回一个隔离级别。

get_records(sql='', parameters=None)[source]

执行 SQL 并返回记录集合。

参数:
get_first(sql='', parameters=None)[source]

执行 SQL 并返回第一行结果。

参数:
run(sql: str | collections.abc.Iterable[str], autocommit: bool = ..., parameters: collections.abc.Iterable | collections.abc.Mapping[str, Any] | None = ..., handler: None = ..., split_statements: bool = ..., return_last: bool = ...) None[source]
run(sql: str | collections.abc.Iterable[str], autocommit: bool = ..., parameters: collections.abc.Iterable | collections.abc.Mapping[str, Any] | None = ..., handler: collections.abc.Callable[[Any], T] = ..., split_statements: bool = ..., return_last: bool = ...) tuple | list[tuple] | list[list[tuple] | tuple] | None

覆盖通用 run 方法,默认将 split_statements 设置为 True。

参数:
  • sql – 要执行的 SQL 语句或语句列表。

  • autocommit – 在查询执行前设置自动提交模式。

  • parameters – 用于渲染 SQL 查询的参数。

  • handler – 可选的可调用对象,用于处理每个语句的结果。

  • split_statements – 如果为 True,则将单个 SQL 字符串拆分为多条语句。

  • return_last – 如果为 True,仅返回最后一条语句的结果。

返回:

查询结果或结果列表。

get_pandas_df(sql='', parameters=None, **kwargs)[source]

执行 SQL 并返回 pandas DataFrame。

参数:
  • sql (str) – 要执行的 SQL 语句(字符串)或要执行的 SQL 语句列表

  • parameters – 用于渲染 SQL 查询的参数。

  • kwargs – (可选)传递给 pandas.io.sql.read_sql 方法的参数。

insert_rows(table, rows, target_fields=None, commit_every=0, replace=False, **kwargs)[source]

以通用方式将一组元组插入表中。

参数:
  • table (str) – 目标表的名称

  • rows (collections.abc.Iterable[tuple]) – 要插入表中的行

  • target_fields (collections.abc.Iterable[str] | None) – 表中要填充的列名

  • commit_every (int) – 单个事务中可插入的最大行数。设置为 0 则在一个事务中插入所有行。

  • replace (bool) – 是否使用替换而非插入

get_openlineage_database_info(connection)[source]

返回 OpenLineage 所需的 Trino 特定信息。

get_openlineage_database_dialect(_)[source]

返回 Trino 方言。

get_openlineage_default_schema()[source]

返回 Trino 默认模式。

get_uri()[source]

返回该连接的 Trino URI。

此条目是否有帮助?