Dataherald / dataherald

Interact with your SQL database, Natural Language to SQL using LLMs
https://dataherald.readthedocs.io/en/latest/
Apache License 2.0
3.36k stars 234 forks source link

Support for Foreign Tables in PostgreSQL Not Currently Available #438

Closed toliver38 closed 7 months ago

toliver38 commented 8 months ago

Issue Description

The current implementation of the database scanner in Dataherald does not support foreign tables in PostgreSQL databases. This limitation restricts the tool's utility in environments where databases extensively use foreign tables for cross-database queries and data integration.

Proposed Solution

I propose enhancing the get_all_tables_and_views method to include foreign tables when scanning PostgreSQL databases. This change involves checking if the database engine is PostgreSQL (psycopg2) and, if so, appending the list of foreign tables to the lists of tables and views. Additionally, the process for generating table examples and processing foreign table columns should be adjusted to handle foreign tables appropriately, by returning an empty example for foreign tables and ensuring that foreign table columns are not processed.

Here is a sketch of the proposed changes:

Initial Testing

I've conducted brief testing of these proposed changes, which suggests they can effectively incorporate foreign table support into Dataherald's PostgreSQL database scanning capabilities. However, I believe there may be more efficient or robust methods to achieve this, and further testing and refinement are necessary.

I have not submitted a pull request at this time, as I'm looking for feedback on the proposed solution and any additional insights that could improve it.

Request for Feedback

I welcome feedback on the proposed solution, including any potential issues or alternative approaches that could enhance support for foreign tables in PostgreSQL databases within Dataherald. If anyone has experience with similar implementations or suggestions for refining this proposal, your insights would be highly appreciated.

jcjc712 commented 8 months ago

Hi @toliver38 thanks for your collaboration.
Actually it looks fine, feel free to create a PR so we can check the branch with the changes, and if we find any issue we could fix it later.

Regards,