From 5a604c4f8b86db90b77bcb5f2346ced89b2ded46 Mon Sep 17 00:00:00 2001 From: Kenzie Tahiri Date: Wed, 1 Jul 2020 15:23:21 -0700 Subject: [PATCH] Just some basic fixes I did just to run queries on both ODBC and REST --- dremio_client/conf/config_default.yaml | 2 ++ dremio_client/dremio_client.py | 14 +++++++++++--- dremio_client/odbc.py | 6 +++--- dremio_client/query.py | 3 ++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/dremio_client/conf/config_default.yaml b/dremio_client/conf/config_default.yaml index afa0bd4..823cdd2 100644 --- a/dremio_client/conf/config_default.yaml +++ b/dremio_client/conf/config_default.yaml @@ -11,3 +11,5 @@ odbc: port: 31010 flight: port: 47470 +rest: + port: 7183 diff --git a/dremio_client/dremio_client.py b/dremio_client/dremio_client.py index 6635086..be4da62 100644 --- a/dremio_client/dremio_client.py +++ b/dremio_client/dremio_client.py @@ -65,17 +65,24 @@ def __init__(self, config): ) self._flight_port = config["flight"]["port"].get(int) self._odbc_port = config["odbc"]["port"].get(int) + self._rest_port = config["rest"]["port"].get(int) self._username = config["auth"]["username"].get() self._password = config["auth"]["password"].get() - self._token = auth(self._base_url, config) + self._rest_url = ( + ("https" if config["ssl"].get(bool) else "http") + + "://" + + self._hostname + + (":{}".format(self._rest_port) if port else "") + ) + self._token = auth(self._rest_url, config) self._ssl_verify = config["verify"].get(bool) - self._catalog = catalog(self._token, self._base_url, self.query, self._ssl_verify) + self._catalog = catalog(self._token, self._rest_url, self.query, self._ssl_verify) self._reflections = list() self._wlm_queues = list() self._wlm_rules = list() self._votes = list() - self._simple = SimpleClient(config) + #self._simple = SimpleClient(config) # took this off because I didn't know how it was intended to be used for now or in the future def simple(self): return self._simple @@ -132,6 +139,7 @@ def query(self, sql, pandas=True, method="flight"): return query( self._token, self._base_url, + self._rest_url, self._hostname, self._odbc_port, self._flight_port, diff --git a/dremio_client/odbc.py b/dremio_client/odbc.py index c35611e..282b7db 100644 --- a/dremio_client/odbc.py +++ b/dremio_client/odbc.py @@ -28,7 +28,7 @@ _WINDOWS_DRIVER = "Dremio Connector" -_OSX_DRIVER = "Dremio ODBC Driver" +_OSX_DRIVER = "/Library/Dremio/ODBC/lib/libdrillodbc_sbu.dylib" # had to add this for the driver path _LINUX32_DRIVER = "Dremio ODBC Driver 32-bit" _LINUX64_DRIVER = "Dremio ODBC Driver 64-bit" _DRIVER = None @@ -41,9 +41,9 @@ def _get_driver_name(): _DRIVER = _LINUX64_DRIVER else: _DRIVER = _LINUX32_DRIVER - if "darwin" in sys.platform: + elif "darwin" in sys.platform: # lines 44 and 46 were not mutually exclusive so decided to change _DRIVER = _OSX_DRIVER - if "win" in sys.platform: + elif "win" in sys.platform: _DRIVER = _WINDOWS_DRIVER logging.debug("Using %s as the odbc driver", _DRIVER) diff --git a/dremio_client/query.py b/dremio_client/query.py index 46e08ac..7bd6179 100644 --- a/dremio_client/query.py +++ b/dremio_client/query.py @@ -39,6 +39,7 @@ def query( token, base_url, + rest_url, hostname, odbc_port, flight_port, @@ -64,7 +65,7 @@ def query( return _odbc_query(sql, hostname=hostname, port=odbc_port, username=username, password=password) except Exception: logging.warning("Unable to run query as odbc, downgrading to rest") - results = _rest_query(token, base_url, sql, ssl_verify=ssl_verify) + results = _rest_query(token, rest_url, sql, ssl_verify=ssl_verify) if pandas and not NO_PANDAS: return pd.DataFrame(results) return list(results)