airflow.providers.presto.hooks.presto

Module Contents

exception airflow.providers.presto.hooks.presto.PrestoException[source]

Bases: Exception

Presto exception

class airflow.providers.presto.hooks.presto.PrestoHook[source]

Bases: airflow.hooks.dbapi.DbApiHook

Interact with Presto through prestodb.

>>> ph = PrestoHook()
>>> sql = "SELECT count(1) AS num FROM airflow.static_babynames"
>>> ph.get_records(sql)
[[340698]]
conn_name_attr = presto_conn_id[source]
default_conn_name = presto_default[source]
conn_type = presto[source]
hook_name = Presto[source]
get_conn(self)[source]

Returns a connection object

get_isolation_level(self)[source]

Returns an isolation level

get_records(self, hql, parameters: Optional[dict] = None)[source]

Get a set of records from Presto

get_first(self, hql: str, parameters: Optional[dict] = None)[source]

Returns only the first row, regardless of how many rows the query returns.

get_pandas_df(self, hql, parameters=None, **kwargs)[source]

Get a pandas dataframe from a sql query.

run(self, hql, autocommit: bool = False, parameters: Optional[dict] = None)[source]

Execute the statement against Presto. Can be used to create views.

insert_rows(self, table: str, rows: Iterable[tuple], target_fields: Optional[Iterable[str]] = None, commit_every: int = 0, replace: bool = False, **kwargs)[source]

A generic way to insert a set of tuples into a table.

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

  • rows (iterable of tuples) -- The rows to insert into the table

  • target_fields (iterable of strings) -- 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

Was this entry helpful?