types.DataSource

DataSource()

An abstract class defining the interface for data sources used by QueryChat.

This class is generic over the DataFrame type returned by execute_query, test_query, and get_data methods.

Attributes

Name Type Description
table_name str Name of the table to be used in SQL queries.

Methods

Name Description
cleanup Clean up resources associated with the data source.
execute_query Execute SQL query and return results.
get_column_metas Return column names and types without running stats queries.
get_data Return the unfiltered data.
get_data_description Get a human-readable data description for the system prompt.
get_db_type Name for the database behind the SQL execution.
get_schema Return schema information about the table as a string.
get_semantic_views_description Get information about semantic views (if any) for the system prompt.
populate_column_stats Populate min/max/categories on the given ColumnMeta list in place.
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.

Returns

Name Type Description
None

execute_query

types.DataSource.execute_query(query)

Execute SQL query and return results.

Parameters

Name Type Description Default
query str SQL query to execute required

Returns

Name Type Description
IntoFrameT Query results

get_column_metas

types.DataSource.get_column_metas()

Return column names and types without running stats queries.

get_data

types.DataSource.get_data()

Return the unfiltered data.

Returns

Name Type Description
IntoFrameT The complete dataset

get_data_description

types.DataSource.get_data_description()

Get a human-readable data description for the system prompt.

Subclasses may override this to provide metadata-derived descriptions (e.g., pin title/description). The default returns an empty string.

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

Name Type Description Default
categorical_threshold int Maximum number of unique values for a text column to be considered categorical required

Returns

Name Type Description
str A string containing the schema information in a format suitable for prompting an LLM about the data structure

get_semantic_views_description

types.DataSource.get_semantic_views_description()

Get information about semantic views (if any) for the system prompt.

populate_column_stats

types.DataSource.populate_column_stats(columns, categorical_threshold)

Populate min/max/categories on the given ColumnMeta list in place.

test_query

types.DataSource.test_query(query, *, require_all_columns=False)

Test SQL query by fetching only one row.

Parameters

Name Type Description Default
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

Name Type Description
IntoFrameT Query results with at most one row

Raises

Name Type Description
MissingColumnsError If require_all_columns is True and result is missing required columns