airflow.providers.trino.hooks.trino

Module Contents

Classes

TrinoHook

Interact with Trino through trino package.

Functions

generate_trino_client_info()

Return json string with dag_id, task_id, execution_date and try_number.

Attributes

T

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

Return json string with dag_id, task_id, execution_date and try_number.

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

Bases: Exception

Trino exception.

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

Bases: airflow.providers.common.sql.hooks.sql.DbApiHook

Interact with Trino through trino package.

>>> 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]
query_id = ''[source]
get_conn()[source]

Return a connection object.

get_isolation_level()[source]

Return an isolation level.

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

Execute the sql and return a set of records.

Parameters
  • sql (str | list[str]) – the sql statement to be executed (str) or a list of sql statements to execute

  • parameters (Iterable | Mapping[str, Any] | None) – The parameters to render the SQL query with.

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

Execute the sql and return the first resulting row.

Parameters
  • sql (str | list[str]) – the sql statement to be executed (str) or a list of sql statements to execute

  • parameters (Iterable | Mapping[str, Any] | None) – The parameters to render the SQL query with.

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

Execute the sql and returns a pandas dataframe.

Parameters
  • sql (str) – the sql statement to be executed (str) or a list of sql statements to execute

  • parameters (Iterable | Mapping[str, Any] | None) – The parameters to render the SQL query with.

  • kwargs – (optional) passed into pandas.io.sql.read_sql method

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

Insert a set of tuples into a table in a generic way.

Parameters
  • table (str) – Name of the target table

  • rows (Iterable[tuple]) – The rows to insert into the table

  • target_fields (Iterable[str] | None) – The names of the columns to fill in the table

  • commit_every (int) – The maximum number of rows to insert in one transaction. Set to 0 to insert all rows in one transaction.

  • replace (bool) – Whether to replace instead of insert

get_openlineage_database_info(connection)[source]

Return Trino specific information for OpenLineage.

get_openlineage_database_dialect(_)[source]

Return Trino dialect.

get_openlineage_default_schema()[source]

Return Trino default schema.

Was this entry helpful?