-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(Views): adding view for local sources (#1586)
* fix(FileManager): updated path in create and pull methods * fix(Views): updated views to reflect refactors * fix(Views): removes commented code and minor changes * feature(Views): adding view for local sources * feature(Views): ruff resolution * fix: update load in cli and pull method * feature(Views): add SQLParser method to parse sql generate to validated one, using, refactor query builders to use sqlglot * feature(QueryBuilder): add checks against SQL injection * test: enforce further sql injection tests --------- Co-authored-by: scaliseraoul-sinaptik <[email protected]> Co-authored-by: Gabriele Venturi <[email protected]>
- Loading branch information
1 parent
3c612d2
commit 8a0123c
Showing
35 changed files
with
923 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import weakref | ||
|
||
import duckdb | ||
|
||
|
||
class DuckDBConnectionManager: | ||
_instance = None | ||
|
||
def __new__(cls): | ||
if cls._instance is None: | ||
cls._instance = super(DuckDBConnectionManager, cls).__new__(cls) | ||
cls._instance._init_connection() | ||
weakref.finalize(cls._instance, cls._close_connection) | ||
return cls._instance | ||
|
||
def _init_connection(self): | ||
"""Initialize a DuckDB connection.""" | ||
self.connection = duckdb.connect() | ||
self._registered_tables = set() | ||
|
||
@classmethod | ||
def _close_connection(cls): | ||
"""Closes the DuckDB connection when the instance is deleted.""" | ||
if cls._instance and hasattr(cls._instance, "connection"): | ||
cls._instance.connection.close() | ||
cls._instance = None | ||
|
||
def register(self, name: str, df): | ||
"""Registers a DataFrame as a DuckDB table.""" | ||
self.connection.register(name, df) | ||
self._registered_tables.add(name) | ||
|
||
def sql(self, query: str): | ||
"""Executes an SQL query and returns the result as a Pandas DataFrame.""" | ||
return self.connection.sql(query) | ||
|
||
def close(self): | ||
"""Manually close the connection if needed.""" | ||
self._close_connection() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.