Skip to content

Commit

Permalink
Use connection handle in create_catalog and drop_catalog (#29)
Browse files Browse the repository at this point in the history
### Summary

Use connection handle in create_catalog and drop_catalog

### Description

Changed from directly calling the login api to using the connection
we've already created.

### Related Issue
#26

### Additional Reviewers
@jlarue26 
@ArgusLi
  • Loading branch information
ravjotbrar authored Oct 18, 2022
1 parent fbbf913 commit f526c4e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down
4 changes: 4 additions & 0 deletions dbt/adapters/dremio/api/handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
from dbt.events import AdapterLogger
logger = AdapterLogger("dremio")


class DremioHandle:
def __init__(self, parameters: Parameters):
self._parameters = parameters
self._cursor = None
self.closed = False

def get_parameters(self):
return self._parameters

def cursor(self):
if self.closed:
raise Exception("HandleClosed")
Expand Down
34 changes: 15 additions & 19 deletions dbt/adapters/dremio/connections.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright (C) 2022 Dremio Corporation
# Copyright (C) 2022 Dremio Corporation

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import agate
Expand Down Expand Up @@ -258,12 +258,10 @@ def execute(
def drop_catalog(self, database, schema):
logger.debug('Dropping schema "{}.{}"', database, schema)

connection = self.get_thread_connection()
thread_connection = self.get_thread_connection()
connection = self.open(thread_connection)
credentials = connection.credentials
api_parameters = self.build_api_parameters(credentials)

token = login(api_parameters)
connection.credentials.token = token
api_parameters = connection.handle.get_parameters()

path_list = self._create_path_list(database, schema)
if database != credentials.datalake:
Expand All @@ -281,12 +279,10 @@ def drop_catalog(self, database, schema):
delete_catalog(api_parameters, catalog_info["id"], ssl_verify=False)

def create_catalog(self, database, schema):
connection = self.get_thread_connection()
thread_connection = self.get_thread_connection()
connection = self.open(thread_connection)
credentials = connection.credentials
api_parameters = self.build_api_parameters(credentials)

token = login(api_parameters)
connection.credentials.token = token
api_parameters = connection.handle.get_parameters()

if database == "@" + credentials.UID:
logger.debug("Database is default: creating folders only")
Expand Down

0 comments on commit f526c4e

Please sign in to comment.