types.DataSource
An abstract class defining the interface for data sources used by QueryChat.
Attributes
| table_name |
str |
Name of the table to be used in SQL queries. |
Methods
| cleanup |
Clean up resources associated with the data source. |
| execute_query |
Execute SQL query and return results as DataFrame. |
| get_data |
Return the unfiltered data as a DataFrame. |
| get_db_type |
Name for the database behind the SQL execution. |
| get_schema |
Return schema information about the table as a string. |
| test_query |
Test SQL query by fetching only one row. |
cleanup
types.DataSource.cleanup()
Clean up resources associated with the data source.
This method should clean up any connections or resources used by the data source.
execute_query
types.DataSource.execute_query(query)
Execute SQL query and return results as DataFrame.
Parameters
| query |
str |
SQL query to execute |
required |
Returns
|
nw.DataFrame |
Query results as a narwhals DataFrame |
get_data
types.DataSource.get_data()
Return the unfiltered data as a DataFrame.
Returns
|
nw.DataFrame |
The complete dataset as a narwhals DataFrame |
get_db_type
types.DataSource.get_db_type()
Name for the database behind the SQL execution.
get_schema
types.DataSource.get_schema(categorical_threshold)
Return schema information about the table as a string.
Parameters
| categorical_threshold |
int |
Maximum number of unique values for a text column to be considered categorical |
required |
Returns
|
str |
A string containing the schema information in a format suitable for prompting an LLM about the data structure |
test_query
types.DataSource.test_query(query, *, require_all_columns=False)
Test SQL query by fetching only one row.
Parameters
| query |
str |
SQL query to test |
required |
| require_all_columns |
bool |
If True, validates that result includes all original table columns. Additional computed columns are allowed. |
False |
Returns
|
nw.DataFrame |
Query results as a narwhals DataFrame with at most one row |
Raises
|
MissingColumnsError |
If require_all_columns is True and result is missing required columns |