| :py:mod:`airflow.providers.trino.hooks.trino` |
| ============================================= |
| |
| .. py:module:: airflow.providers.trino.hooks.trino |
| |
| |
| Module Contents |
| --------------- |
| |
| Classes |
| ~~~~~~~ |
| |
| .. autoapisummary:: |
| |
| airflow.providers.trino.hooks.trino.TrinoHook |
| |
| |
| |
| Functions |
| ~~~~~~~~~ |
| |
| .. autoapisummary:: |
| |
| airflow.providers.trino.hooks.trino.generate_trino_client_info |
| |
| |
| |
| Attributes |
| ~~~~~~~~~~ |
| |
| .. autoapisummary:: |
| |
| airflow.providers.trino.hooks.trino.DEFAULT_FORMAT_PREFIX |
| |
| |
| .. py:data:: DEFAULT_FORMAT_PREFIX |
| :annotation: = airflow.ctx. |
| |
| |
| |
| .. py:function:: generate_trino_client_info() |
| |
| Return json string with dag_id, task_id, execution_date and try_number |
| |
| |
| .. py:exception:: TrinoException |
| |
| Bases: :py:obj:`Exception` |
| |
| Trino exception |
| |
| |
| .. py:class:: TrinoHook(*args, schema = None, log_sql = True, **kwargs) |
| |
| Bases: :py:obj:`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]] |
| |
| .. py:attribute:: conn_name_attr |
| :annotation: = trino_conn_id |
| |
| |
| |
| .. py:attribute:: default_conn_name |
| :annotation: = trino_default |
| |
| |
| |
| .. py:attribute:: conn_type |
| :annotation: = trino |
| |
| |
| |
| .. py:attribute:: hook_name |
| :annotation: = Trino |
| |
| |
| |
| .. py:attribute:: query_id |
| :annotation: = |
| |
| |
| |
| .. py:method:: get_conn() |
| |
| Returns a connection object |
| |
| |
| .. py:method:: get_isolation_level() |
| |
| Returns an isolation level |
| |
| |
| .. py:method:: get_records(sql = '', parameters = None, **kwargs) |
| |
| Executes the sql and returns a set of records. |
| |
| :param sql: the sql statement to be executed (str) or a list of |
| sql statements to execute |
| :param parameters: The parameters to render the SQL query with. |
| |
| |
| .. py:method:: get_first(sql = '', parameters = None) |
| |
| Executes the sql and returns the first resulting row. |
| |
| :param sql: the sql statement to be executed (str) or a list of |
| sql statements to execute |
| :param parameters: The parameters to render the SQL query with. |
| |
| |
| .. py:method:: get_pandas_df(sql = '', parameters = None, **kwargs) |
| |
| Executes the sql and returns a pandas dataframe |
| |
| :param sql: the sql statement to be executed (str) or a list of |
| sql statements to execute |
| :param parameters: The parameters to render the SQL query with. |
| :param kwargs: (optional) passed into pandas.io.sql.read_sql method |
| |
| |
| .. py:method:: run(sql, autocommit = False, parameters = None, handler = None, split_statements = False, return_last = True) |
| |
| Runs a command or a list of commands. Pass a list of sql |
| statements to the sql parameter to get them to execute |
| sequentially |
| |
| :param sql: the sql statement to be executed (str) or a list of |
| sql statements to execute |
| :param autocommit: What to set the connection's autocommit setting to |
| before executing the query. |
| :param parameters: The parameters to render the SQL query with. |
| :param handler: The result handler which is called with the result of each statement. |
| :param split_statements: Whether to split a single SQL string into statements and run separately |
| :param return_last: Whether to return result for only last statement or for all after split |
| :return: return only result of the ALL SQL expressions if handler was provided. |
| |
| |
| .. py:method:: insert_rows(table, rows, target_fields = None, commit_every = 0, replace = False, **kwargs) |
| |
| A generic way to insert a set of tuples into a table. |
| |
| :param table: Name of the target table |
| :param rows: The rows to insert into the table |
| :param target_fields: The names of the columns to fill in the table |
| :param commit_every: The maximum number of rows to insert in one |
| transaction. Set to 0 to insert all rows in one transaction. |
| :param replace: Whether to replace instead of insert |
| |
| |
| .. py:method:: test_connection() |
| |
| Tests the connection from UI using Trino specific query |
| |
| |
| |