airflow.providers.trino.hooks.trino¶
属性¶
异常¶
Trino 异常。 |
类¶
通过 trino 包与 Trino 交互。 |
函数¶
返回包含 dag_id、task_id、logical_date 和 try_number 的 JSON 字符串。 |
模块内容¶
- airflow.providers.trino.hooks.trino.generate_trino_client_info()[source]¶
返回包含 dag_id、task_id、logical_date 和 try_number 的 JSON 字符串。
- 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]]
- get_records(sql='', parameters=None)[source]¶
执行 SQL 并返回记录集合。
- 参数:
parameters (collections.abc.Iterable | collections.abc.Mapping[str, Any] | None) – 用于渲染 SQL 查询的参数。
- get_first(sql='', parameters=None)[source]¶
执行 SQL 并返回第一行结果。
- 参数:
parameters (collections.abc.Iterable | collections.abc.Mapping[str, Any] | None) – 用于渲染 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) – 是否使用替换而非插入