Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SnowFlake): snowflake connector #574

Merged
merged 10 commits into from
Sep 19, 2023
Merged

Conversation

ArslanSaleem
Copy link
Collaborator

@ArslanSaleem ArslanSaleem commented Sep 19, 2023

Connects to snowflake data source by providing credentials

Summary by CodeRabbit

  • New Feature: Added support for Snowflake Data Cloud through the new SnowFlakeConnector class.
  • New Feature: Enhanced the SQL connector with a more flexible configuration system, introducing SQLConnectorConfig.
  • New Feature: Introduced YahooFinanceConnectorConfig to provide a more tailored configuration for Yahoo Finance connections.
  • Refactor: Renamed ConnectorConfig to BaseConnectorConfig and introduced derived classes for specific connectors.
  • Test: Added comprehensive unit tests for the new SnowFlakeConnector class.
  • New Feature: Updated examples to demonstrate usage of the new Snowflake and Yahoo Finance connectors.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2023

Walkthrough

This update introduces new connector configurations for Yahoo Finance and Snowflake, refactors existing SQL connectors, and adds corresponding unit tests. It also includes examples demonstrating how to use these connectors with the pandasai library.

Changes

File(s) Summary
examples/from_snowflake.py,
examples/from_yahoo_finance.py
Added examples of using pandasai with Snowflake and Yahoo Finance.
pandasai/connectors/__init__.py Exported SnowFlakeConnector class.
pandasai/connectors/base.py Introduced BaseConnectorConfig and derived classes for specific connectors. Added _load_connector_config and _init_connection methods to BaseConnector.
pandasai/connectors/sql.py Refactored SQLConnector and added SnowFlakeConnector. Updated head() method to include caching.
pandasai/connectors/yahoo_finance.py Updated YahooFinanceConnector to use new configuration class and added _load_connector_config and _init_connection methods.
tests/connectors/test_base.py,
tests/connectors/test_sql.py,
tests/connectors/test_snowflake.py
Updated tests to reflect changes in connector configurations and added new tests for SnowFlakeConnector.

🐇💻

Code hopping through the fields,

Connectors spinning like wheels.

Yahoo Finance, Snowflake too,

With pandasai, there's so much to do!

Tests are green, the code is neat,

This rabbit thinks it's pretty sweet! 🥕🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 10

Commits Files that changed from the base of the PR and between 5464a4d and 9d76342.
Files ignored due to filter (1)
  • pyproject.toml
Files selected for processing (7)
  • examples/from_snowflake.py (1 hunks)
  • pandasai/connectors/init.py (2 hunks)
  • pandasai/connectors/base.py (2 hunks)
  • pandasai/connectors/sql.py (6 hunks)
  • pandasai/connectors/yahoo_finance.py (3 hunks)
  • tests/connectors/test_base.py (2 hunks)
  • tests/connectors/test_sql.py (2 hunks)
Files skipped from review due to trivial changes (2)
  • pandasai/connectors/init.py
  • tests/connectors/test_base.py
Additional comments (Suppressed): 10
tests/connectors/test_sql.py (2)
  • 1-7: The import statement for the configuration class has been updated to reflect the new SQLConnectorConfig class. Ensure that this change is reflected throughout the codebase.

  • 16-22: The ConnectorConfig instance has been replaced with a SQLConnectorConfig instance. Make sure that all properties required by SQLConnectorConfig are provided and that they are valid.

pandasai/connectors/yahoo_finance.py (2)
  • 1-8: The import of create_engine from sqlalchemy and the renaming of ConnectorConfig to YahooFinanceConnectorConfig in line 5 are new additions. Ensure that these changes do not break any existing functionality or dependencies elsewhere in the codebase.

  • 23-30: The YahooFinanceConnectorConfig object is now being initialized without a username and password, which were present in the old hunk. If the Yahoo Finance API requires authentication, this could be an issue. Please verify if these credentials are necessary for the connection.

pandasai/connectors/sql.py (6)
  • 27-28: The __init__ method of the SQLConnector class now accepts a union type for the config parameter, which can be either a BaseConnectorConfig object or a dictionary. This change provides more flexibility in how the configuration is passed to the connector. However, it's important to ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 34-35: The config object is loaded using the _load_connector_config method before being passed to the parent class constructor. This approach allows for additional processing of the configuration before it's used to initialize the base class. However, it's crucial to verify that the _load_connector_config method correctly handles both BaseConnectorConfig objects and dictionaries.

  • 365-366: The __init__ method of the MySQLConnector class now accepts a SQLConnectorConfig object instead of a ConnectorConfig object. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 394-395: The __init__ method of the PostgreSQLConnector class now accepts a SQLConnectorConfig object instead of a ConnectorConfig object. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 445-466: The __init__ method of the SnowFlakeConnector class sets default values for various configuration parameters using environment variables if they're not provided in the config object. This approach provides flexibility and allows sensitive information like usernames and passwords to be stored securely in environment variables. However, it's important to ensure that these environment variables are set correctly in the deployment environment.

  • 486-506: The head method of the SnowFlakeConnector class is decorated with the cache decorator from the functools module. This decorator caches the result of the method and returns the cached result on subsequent calls with the same arguments. This can significantly improve performance when retrieving the head of the data source multiple times. However, it's important to consider the implications of caching in terms of memory usage and data freshness.

examples/from_snowflake.py Outdated Show resolved Hide resolved
examples/from_snowflake.py Outdated Show resolved Hide resolved
pandasai/connectors/base.py Outdated Show resolved Hide resolved
pandasai/connectors/yahoo_finance.py Outdated Show resolved Hide resolved
pandasai/connectors/yahoo_finance.py Outdated Show resolved Hide resolved
pandasai/connectors/sql.py Outdated Show resolved Hide resolved
pandasai/connectors/sql.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 3

Commits Files that changed from the base of the PR and between 9d76342 and 5b47140.
Files selected for processing (2)
  • pandasai/connectors/base.py (2 hunks)
  • pandasai/connectors/yahoo_finance.py (3 hunks)
Additional comments (Suppressed): 3
pandasai/connectors/yahoo_finance.py (3)
  • 1-7: The import of the YahooFinanceConnectorConfig class has been updated to reflect the new class name. This change is consistent with the PR summary and seems to be correctly implemented.

  • 22-29: The instantiation of the YahooFinanceConnectorConfig object has been updated to remove the username and password parameters, which are not needed for Yahoo Finance. This change improves security by not storing unnecessary credentials.

  • 33-36: The initialization of the YahooFinanceConnector class remains largely unchanged, except for the use of the new YahooFinanceConnectorConfig class. The changes are consistent with the PR summary and seem to be correctly implemented.

pandasai/connectors/base.py Outdated Show resolved Hide resolved
pandasai/connectors/base.py Outdated Show resolved Hide resolved
pandasai/connectors/base.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@gventuri gventuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! I'd ass some tests for the new connector, then we can merge :)


OPEN_AI_API = "Your-API-Key"
llm = OpenAI(api_token=OPEN_AI_API)
df = SmartDatalake([snowflake_connector], config={"llm": llm})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess since it's a single connector, we can use the SmartDatframe here instead, like this:

df = SmartDatframe(snowflake_connector, config={"llm": llm})

@@ -34,7 +33,7 @@ def __init__(self, stock_ticker, where=None, cache_interval: int = 600):
self._cache_interval = cache_interval
super().__init__(yahoo_finance_config)
self.ticker = yfinance.Ticker(self._config.table)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover

@ArslanSaleem
Copy link
Collaborator Author

WIP

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2023

Rate Limit Exceeded

You have exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 0 minutes and 17 seconds before requesting another review.

To re-trigger a review, convert this PR to a draft and then mark it as ready for review again. Alternatively, you can push a new commit to this PR.

@codecov-commenter
Copy link

codecov-commenter commented Sep 19, 2023

Codecov Report

Merging #574 (e3ef537) into main (5464a4d) will decrease coverage by 0.04%.
The diff coverage is 85.93%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            Coverage Diff             @@
##             main     #574      +/-   ##
==========================================
- Coverage   83.32%   83.28%   -0.04%     
==========================================
  Files          53       53              
  Lines        2602     2651      +49     
==========================================
+ Hits         2168     2208      +40     
- Misses        434      443       +9     
Files Changed Coverage Δ
pandasai/connectors/sql.py 62.13% <82.50%> (+3.41%) ⬆️
pandasai/connectors/base.py 86.15% <90.47%> (+0.15%) ⬆️
pandasai/connectors/__init__.py 100.00% <100.00%> (ø)
pandasai/connectors/yahoo_finance.py 76.81% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 14

Commits Files that changed from the base of the PR and between 5b47140 and e3ef537.
Files selected for processing (5)
  • examples/from_snowflake.py (1 hunks)
  • examples/from_yahoo_finance.py (1 hunks)
  • pandasai/connectors/base.py (2 hunks)
  • pandasai/connectors/sql.py (6 hunks)
  • tests/connectors/test_snowflake.py (1 hunks)
Additional comments (Suppressed): 9
tests/connectors/test_snowflake.py (2)
  • 22-24: The values for username, password, and account are placeholders ("your_username", "your_password", "ehxzojy-ue47135"). Ensure that these are replaced with valid credentials during testing. If these are meant to be placeholders, consider making it more explicit, e.g., "YOUR_USERNAME_HERE".

  • 51-58: The _build_query method is being tested here, but it's not clear whether SQL injection attacks have been considered. Ensure that the query building process is safe from SQL injection attacks by using parameterized queries or other secure practices.

pandasai/connectors/base.py (1)
  • 75-90: The _load_connector_config() and _init_connection() methods have been added but they don't contain any implementation. If these methods are intended to be abstract and implemented by subclasses, they should be decorated with the @abstractmethod decorator. Otherwise, they should include some basic implementation that can be extended or overridden by subclasses.
pandasai/connectors/sql.py (6)
  • 8-12: The import statements have been updated to include the new SnowFlakeConnectorConfig class and the refactored BaseConnectorConfig class. Ensure that these classes are correctly implemented and available in the .base module.

  • 38-39: The _load_connector_config() method is called to process the config argument. This method should handle both BaseConnectorConfig objects and dictionaries, converting them into a SQLConnectorConfig object. Ensure that this method is correctly implemented and handles all possible types and formats of the config argument.

  • 44-45: The _init_connection() method is called to initialize the database connection using the config argument. Ensure that this method is correctly implemented and establishes a secure and reliable connection to the database.

  • 46-47: The cache interval is set after the connection has been initialized. This order of operations seems logical, but make sure that the cache interval does not need to be set before the connection is established for any reason.

  • 58-59: The _load_connector_config() method is expected to convert the config argument into a SQLConnectorConfig object. Make sure that this method correctly handles all possible types and formats of the config argument.

  • 446-528: The new SnowFlakeConnector class extends the SQLConnector class and provides functionality for connecting to Snowflake databases. It overrides the _load_connector_config(), _init_connection(), head(), and __repr__() methods, and adds additional configuration properties specific to Snowflake databases. Ensure that these methods are correctly implemented and provide the expected functionality.

examples/from_yahoo_finance.py Show resolved Hide resolved
examples/from_snowflake.py Show resolved Hide resolved
examples/from_snowflake.py Show resolved Hide resolved
tests/connectors/test_snowflake.py Show resolved Hide resolved
tests/connectors/test_snowflake.py Show resolved Hide resolved
pandasai/connectors/base.py Show resolved Hide resolved
pandasai/connectors/base.py Show resolved Hide resolved
pandasai/connectors/sql.py Show resolved Hide resolved
pandasai/connectors/sql.py Show resolved Hide resolved
pandasai/connectors/sql.py Show resolved Hide resolved
@gventuri gventuri changed the title Feat(SnowFlake): Connector for snowflake feat(SnowFlake): snowflake connector Sep 19, 2023
@gventuri gventuri merged commit 58559db into main Sep 19, 2023
gventuri pushed a commit that referenced this pull request Sep 25, 2023
* Add Basic code for SnowFlake Connector

* feat[Snowflake]: Adding SnowFlake Connector

* fix: missing , in where clause of example

* test: snowflake parser improvements

* fix: Yahoo connector

* fix: ruff issues

* fix: example of yahoo finance

* Adding test cases for snowflake

* fix doc string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants