Skip to content

Datainput

flowtask.components.DataInput

DataInput

DataInput(loop=None, job=None, stat=None, **kwargs)

Bases: DbClient, TemplateSupport, FlowComponent

DataInput

Class to execute queries against a database and retrieve results using asyncDB.

Inherits from both DbClient (for database connection management) and FlowComponent (for component lifecycle management).

.. table:: Properties :widths: auto

+---------------+----------+------------------------------------------------------------------------------+
| Name          | Required | Description                                                                  |
+---------------+----------+------------------------------------------------------------------------------+
| driver        |   Yes    | asyncDB driver to use (defaults to "pg" for PostgreSQL).                     |
|               |          | Can be overridden by a "driver" key in the "credentials" dictionary.         |
+---------------+----------+------------------------------------------------------------------------------+
| credentials   |   Yes    | Dictionary containing database connection credentials (user, password, etc.).|
+---------------+----------+------------------------------------------------------------------------------+
| query         |   Yes    | SQL query or queries to be executed. Can be provided in different formats:   |
|               |          |  * String (single query)                                                     |
|               |          |  * List (multiple queries)                                                   |
|               |          |  * Dictionary (named queries) - key-value pairs where key is the query name  |
|               |          |    and value is the query string.                                            |
|               |          | If not provided, no queries will be executed.                                |
+---------------+----------+------------------------------------------------------------------------------+
| file          |   Yes    | Path to a file containing a single or multiple SQL queries (alternative to   |
|               |          | `query`).                                                                    |
|               |          | If provided along with `query`, `file` takes precedence.                     |
+---------------+----------+------------------------------------------------------------------------------+
| as_dataframe  |    No    | Boolean flag indicating whether to convert query results to DataFrames.      |
|               |          | Defaults to False (returns raw results).                                     |
+---------------+----------+------------------------------------------------------------------------------+

.. returns:: The return value depends on the number of queries executed and the as_dataframe property: * Single Query: * DataFrame (if as_dataframe is True): Pandas DataFrame containing the query results. * raw result object (default): Raw result object specific to the database driver. * Multiple Queries: * List[DataFrame] (if as_dataframe is True): List of DataFrames, each corresponding to a query result. * List[raw result object] (default): List of raw result objects, each representing a query result. Returns None if no queries are provided.

Example:

```yaml
DataInput:
  query: SELECT * FROM xfinity.product_types
  as_string: true
```