qlty_standardDeviation
Calculate standard deviation for a specific column in a Teradata database table to assess data variability. Input database, table, and column names to obtain query results with metadata.
Instructions
Get the standard deviation from column in a table.
Arguments: database_name - name of the database table_name - table name to analyze column_name - column name to analyze
Returns: ResponseType: formatted response with query results + metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| col_name | Yes | ||
| database_name | Yes | ||
| table_name | Yes |
Implementation Reference
- The handler function for the 'qlty_standardDeviation' tool. It connects to Teradata, constructs a query using TD_UnivariateStatistics to compute MEAN and STD for the specified column in the table, fetches the results, formats them into JSON, adds metadata, and returns a response.def handle_qlty_standardDeviation( conn: TeradataConnection, database_name: str | None, table_name: str, column_name: str, *args, **kwargs ): """ Get the standard deviation from column in a table. Arguments: database_name - name of the database table_name - table name to analyze column_name - column name to analyze Returns: ResponseType: formatted response with query results + metadata """ logger.debug(f"Tool: handle_qlty_standardDeviation: Args: table_name: {database_name}.{table_name}, column_name: {column_name}") if database_name is not None: table_name = f"{database_name}.{table_name}" with conn.cursor() as cur: rows = cur.execute(f"select * from TD_UnivariateStatistics ( on {table_name} as InputTable using TargetColumns ('{column_name}') Stats('MEAN','STD')) as dt ORDER BY 1,2") data = rows_to_json(cur.description, rows.fetchall()) metadata = { "tool_name": "qlty_standardDeviation", "database_name": database_name, "table_name": table_name, "column_name": column_name, "stats_calculated": ["MEAN", "STD"], "rows": len(data) } logger.debug(f"Tool: handle_qlty_standardDeviation: Metadata: {metadata}") return create_response(data, metadata)