airflow.providers.presto.hooks.presto

Module Contents

Classes

PrestoHook

Interact with Presto through prestodb.

Functions

generate_presto_client_info()

Return json string with dag_id, task_id, execution_date and try_number

Attributes

DEFAULT_FORMAT_PREFIX

airflow.providers.presto.hooks.presto.DEFAULT_FORMAT_PREFIX = airflow.ctx.[source]
airflow.providers.presto.hooks.presto.generate_presto_client_info()[source]

Return json string with dag_id, task_id, execution_date and try_number

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

Bases: Exception

Presto exception

class airflow.providers.presto.hooks.presto.PrestoHook(*args, schema=None, log_sql=True, **kwargs)[source]

Bases: airflow.providers.common.sql.hooks.sql.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]
placeholder = ?[source]
get_conn()[source]

Returns a connection object

get_isolation_level()[source]

Returns an isolation level

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

Executes the sql and returns a set of records.

Parameters
  • sql (Union[str, List[str]]) -- the sql statement to be executed (str) or a list of sql statements to execute

  • parameters (Optional[Union[Iterable, Mapping]]) -- The parameters to render the SQL query with.

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

Executes the sql and returns the first resulting row.

Parameters
  • sql (Union[str, List[str]]) -- the sql statement to be executed (str) or a list of sql statements to execute

  • parameters (Optional[dict]) -- The parameters to render the SQL query with.

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

Executes 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

run(sql, autocommit=False, parameters=None, handler=None, split_statements=False, return_last=True)[source]

Runs a command or a list of commands. Pass a list of sql statements to the sql parameter to get them to execute sequentially

Parameters
  • sql (Union[str, Iterable[str]]) -- the sql statement to be executed (str) or a list of sql statements to execute

  • autocommit (bool) -- What to set the connection's autocommit setting to before executing the query.

  • parameters (Optional[Union[Iterable, Mapping]]) -- The parameters to render the SQL query with.

  • handler (Optional[Callable]) -- The result handler which is called with the result of each statement.

  • split_statements (bool) -- Whether to split a single SQL string into statements and run separately

  • return_last (bool) -- Whether to return result for only last statement or for all after split

Returns

return only result of the ALL SQL expressions if handler was provided.

Return type

Optional[Union[Any, List[Any]]]

insert_rows(table, rows, target_fields=None, commit_every=0, replace=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[tuple]) -- The rows to insert into the table

  • target_fields (Optional[Iterable[str]]) -- 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?