This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1120 from chaos-genius/develop
Merge develop into the main for v0.10.2 release
- Loading branch information
Showing
19 changed files
with
306 additions
and
95 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
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,76 @@ | ||
import pandas as pd | ||
from sqlalchemy import create_engine | ||
from sqlalchemy import text | ||
from .base_db import BaseDb | ||
from .connector_utils import merge_dataframe_chunks | ||
|
||
|
||
class ClickHouseDb(BaseDb): | ||
|
||
__SQL_IDENTIFIER = "`" | ||
|
||
@property | ||
def sql_identifier(self): | ||
"""Used to quote any SQL identifier in case of it using special characters or keywords.""" | ||
return self.__SQL_IDENTIFIER | ||
|
||
db_name = "ClickHouse" | ||
test_db_query = "SELECT 1" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
def get_db_uri(self): | ||
db_info = self.ds_info | ||
host = db_info.get("host") | ||
port = int(db_info.get("port")) | ||
username = db_info.get("username") | ||
database = db_info.get("database") | ||
password = db_info.get("password") | ||
if not (host and port and username and password and database): | ||
raise NotImplementedError( | ||
"Database Credential not found for ClickHouse." | ||
) | ||
self.sqlalchemy_db_uri = ( | ||
f"clickhouse+native://{username}:{password}@{host}:{port}/{database}" | ||
) | ||
return self.sqlalchemy_db_uri | ||
|
||
def get_db_engine(self): | ||
db_uri = self.get_db_uri() | ||
self.engine = create_engine(db_uri, echo=self.debug) | ||
return self.engine | ||
|
||
def test_connection(self): | ||
if not hasattr(self, "engine") or not self.engine: | ||
self.engine = self.get_db_engine() | ||
query_text = text(self.test_db_query) | ||
status, message = None, "" | ||
try: | ||
with self.engine.connect() as connection: | ||
cursor = connection.execute(query_text) | ||
results = cursor.all() | ||
if results[0][0] == 1: | ||
status = True | ||
else: | ||
status = False | ||
except Exception as err_msg: | ||
status = False | ||
message = str(err_msg) | ||
return status, message | ||
|
||
def run_query(self, query, as_df=True): | ||
engine = self.get_db_engine() | ||
if as_df == True: | ||
return merge_dataframe_chunks( | ||
pd.read_sql_query(query, engine, chunksize=self.CHUNKSIZE) | ||
) | ||
else: | ||
return [] | ||
|
||
def get_schema(self): | ||
self.schema = self.ds_info.get("database") | ||
return self.schema | ||
|
||
def get_schema_names_list(self): | ||
return None |
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
Large diffs are not rendered by default.
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.