airflow.providers.common.sql.hooks.handlers

Module Contents

Functions

return_single_query_results(sql, return_last, ...)

Determine when results of single query only should be returned.

fetch_all_handler(cursor)

Return results for DbApiHook.run().

fetch_one_handler(cursor)

Return first result for DbApiHook.run().

airflow.providers.common.sql.hooks.handlers.return_single_query_results(sql, return_last, split_statements)[source]

Determine when results of single query only should be returned.

For compatibility reasons, the behaviour of the DBAPIHook is somewhat confusing. In some cases, when multiple queries are run, the return value will be an iterable (list) of results – one for each query. However, in other cases, when single query is run, the return value will be just the result of that single query without wrapping the results in a list.

The cases when single query results are returned without wrapping them in a list are as follows:

  1. sql is string and return_last is True (regardless what split_statements value is)

  2. sql is string and split_statements is False

In all other cases, the results are wrapped in a list, even if there is only one statement to process. In particular, the return value will be a list of query results in the following circumstances:

  1. when sql is an iterable of string statements (regardless what return_last value is)

  2. when sql is string, split_statements is True and return_last is False

Parameters
  • sql (str | collections.abc.Iterable[str]) – sql to run (either string or list of strings)

  • return_last (bool) – whether last statement output should only be returned

  • split_statements (bool | None) – whether to split string statements.

Returns

True if the hook should return single query results

airflow.providers.common.sql.hooks.handlers.fetch_all_handler(cursor)[source]

Return results for DbApiHook.run().

airflow.providers.common.sql.hooks.handlers.fetch_one_handler(cursor)[source]

Return first result for DbApiHook.run().

Was this entry helpful?