-
Notifications
You must be signed in to change notification settings - Fork 0
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 #11 from GSK-Biostatistics/feature/hive-loader
Feature/hive loader
- Loading branch information
Showing
5 changed files
with
47 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from data_loaders.file_data_loader import FileDataLoader | ||
from data_loaders.sql_server_data_loader import SQLServerDataLoader | ||
from data_loaders.azure_data_loader import AzureDataLoader | ||
from data_loaders.hive_data_loader import HiveDataLoader |
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,43 @@ | ||
import neointerface | ||
import os | ||
import jaydebeapi | ||
import pandas as pd | ||
|
||
|
||
class HiveDataLoader: | ||
def __init__(self, | ||
db_host=os.environ.get("HIVE_SERVER"), | ||
schema=os.environ.get("HIVE_SCHEMA"), | ||
user=os.environ.get("HIVE_USER_ID"), | ||
password=os.environ.get("HIVE_PASSWORD"), | ||
driver_path=os.environ.get("HIVE_JDBC_DRIVER_PATH"), | ||
driver_class=os.environ.get("HIVE_JDBC_DRIVER"), | ||
*args, **kwargs): | ||
self._connection = None | ||
self._schema = schema | ||
self._driver_class = driver_class | ||
self._db_host = db_host | ||
self._user = user | ||
self._password = password | ||
self._driver_path = driver_path | ||
|
||
def open(self): | ||
self._connection = jaydebeapi.connect(self._driver_class, f'jdbc:hive2://{self._db_host}/{self._schema}', | ||
{'UID': self._user, 'PWD': self._password, 'AuthMech': "3"}, self._driver_path) | ||
|
||
def query(self, statement: str): | ||
cursor = self._connection.cursor() | ||
cursor.execute(statement) | ||
results = cursor.fetchall() | ||
names = [item[0] for item in cursor.description] | ||
df = pd.DataFrame(results) | ||
df.columns = names | ||
cursor.close() | ||
return df | ||
|
||
def get_tables(self): | ||
tables_df = self.query(f'show tables from {self._schema}') | ||
return tables_df | ||
|
||
def close(self): | ||
self._connection.close() |
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 |
---|---|---|
|
@@ -10,3 +10,4 @@ azure-identity==1.6.0 | |
datacompy==0.7.2 | ||
colorlog==6.6.0 | ||
PyGithub==1.55 | ||
jaydebeapi==1.2.3 |
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 |
---|---|---|
|
@@ -10,3 +10,4 @@ azure-identity==1.6.0 | |
datacompy==0.7.2 | ||
colorlog==6.6.0 | ||
PyGithub==1.55 | ||
jaydebeapi==1.2.3 |
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