airflow.providers.trino.hooks.trino

Attributes

T

Exceptions

TrinoException

Trino exception.

Classes

TrinoHook

Interact with Trino through trino package.

Functions

generate_trino_client_info()

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

Module Contents

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, logical_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]
strip_semicolon = True[source]
query_id = ''[source]
classmethod get_ui_field_behaviour()[source]

Return custom field behaviour.

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:
get_first(sql='', parameters=None)[source]

Execute the sql and return the first resulting row.

Parameters:
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

Override common run to set split_statements=True by default.

Parameters:
  • sql – SQL statement or list of statements to execute.

  • autocommit – Set autocommit mode before query execution.

  • parameters – Parameters to render the SQL query with.

  • handler – Optional callable to process each statement result.

  • split_statements – Split single SQL string into statements if True.

  • return_last – Return only last statement result if True.

Returns:

Query result or list of results.

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 – 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 (collections.abc.Iterable[tuple]) – The rows to insert into the table

  • target_fields (collections.abc.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.

get_uri()[source]

Return the Trino URI for the connection.

Was this entry helpful?