Skip to content

Commit 31d5913

Browse files
committed
Revert "oracle connection from secret"
This reverts commit 3082241.
1 parent db654f3 commit 31d5913

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

ads/oracledb/oracle_db.py

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*--
23

3-
# Copyright (c) 2021, 2024 Oracle and/or its affiliates.
4+
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
45
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
56

67
"""
@@ -16,20 +17,19 @@
1617
Note: We need to account for cx_Oracle though oracledb can operate in thick mode. The end user may be is using one of the old conda packs or an environment where cx_Oracle is the only available driver.
1718
"""
1819

20+
from ads.common.utils import ORACLE_DEFAULT_PORT
21+
1922
import logging
23+
import numpy as np
2024
import os
25+
import pandas as pd
2126
import tempfile
22-
import zipfile
2327
from time import time
24-
from typing import Dict, Iterator, List, Optional, Union
25-
26-
import numpy as np
27-
import pandas as pd
28-
28+
from typing import Dict, Optional, List, Union, Iterator
29+
import zipfile
2930
from ads.common.decorator.runtime_dependency import (
3031
OptionalDependency,
3132
)
32-
from ads.common.utils import ORACLE_DEFAULT_PORT
3333

3434
logger = logging.getLogger("ads.oracle_connector")
3535
CX_ORACLE = "cx_Oracle"
@@ -40,17 +40,17 @@
4040
import oracledb as oracle_driver # Both the driver share same signature for the APIs that we are using.
4141

4242
PYTHON_DRIVER_NAME = PYTHON_ORACLEDB
43-
except ModuleNotFoundError as err:
43+
except:
4444
logger.info("oracledb package not found. Trying to load cx_Oracle")
4545
try:
4646
import cx_Oracle as oracle_driver
4747

4848
PYTHON_DRIVER_NAME = CX_ORACLE
49-
except ModuleNotFoundError as err2:
50-
raise ModuleNotFoundError (
49+
except ModuleNotFoundError:
50+
raise ModuleNotFoundError(
5151
f"Neither `oracledb` nor `cx_Oracle` module was not found. Please run "
5252
f"`pip install {OptionalDependency.DATA}`."
53-
) from err2
53+
)
5454

5555

5656
class OracleRDBMSConnection(oracle_driver.Connection):
@@ -75,7 +75,7 @@ def __init__(
7575
logger.info(
7676
"Running oracledb driver in thick mode. For mTLS based connection, thick mode is default."
7777
)
78-
except Exception as err:
78+
except:
7979
logger.info(
8080
"Could not use thick mode. The driver is running in thin mode. System might prompt for passphrase"
8181
)
@@ -154,6 +154,7 @@ def insert(
154154
batch_size=100000,
155155
encoding="utf-8",
156156
):
157+
157158
if if_exists not in ["fail", "replace", "append"]:
158159
raise ValueError(
159160
f"Unknown option `if_exists`={if_exists}. Valid options are 'fail', 'replace', 'append'"
@@ -172,6 +173,7 @@ def insert(
172173
df_orcl.columns = df_orcl.columns.str.replace(r"\W+", "_", regex=True)
173174
table_exist = True
174175
with self.cursor() as cursor:
176+
175177
if if_exists != "replace":
176178
try:
177179
cursor.execute(f"SELECT 1 from {table_name} FETCH NEXT 1 ROWS ONLY")
@@ -273,6 +275,7 @@ def chunks(lst: List, batch_size: int):
273275
yield lst[i : i + batch_size]
274276

275277
for batch in chunks(record_data, batch_size=batch_size):
278+
276279
cursor.executemany(sql, batch, batcherrors=True)
277280

278281
for error in cursor.getbatcherrors():
@@ -301,6 +304,7 @@ def _fetch_by_batch(self, cursor, chunksize):
301304
def query(
302305
self, sql: str, bind_variables: Optional[Dict], chunksize=None
303306
) -> Union[pd.DataFrame, Iterator[pd.DataFrame]]:
307+
304308
start_time = time()
305309

306310
cursor = self.cursor()
@@ -311,8 +315,10 @@ def query(
311315
cursor.execute(sql, **bind_variables)
312316
columns = [row[0] for row in cursor.description]
313317
df = iter(
314-
pd.DataFrame(data=rows, columns=columns)
315-
for rows in self._fetch_by_batch(cursor, chunksize)
318+
(
319+
pd.DataFrame(data=rows, columns=columns)
320+
for rows in self._fetch_by_batch(cursor, chunksize)
321+
)
316322
)
317323

318324
else:
@@ -326,21 +332,3 @@ def query(
326332
)
327333

328334
return df
329-
330-
331-
def get_adw_connection(vault_secret_id: str) -> "oracledb.Connection":
332-
"""Creates ADW connection from the credentials stored in the vault"""
333-
import oracledb
334-
335-
from ads.secrets.adb import ADBSecretKeeper
336-
337-
secret = vault_secret_id
338-
339-
logging.getLogger().debug(f"The secret id is: {secret}")
340-
creds = ADBSecretKeeper.load_secret(secret).to_dict()
341-
user = creds.pop("user_name", None)
342-
password = creds.pop("password", None)
343-
if not user or not password:
344-
raise ValueError(f"The user or password is missing in {secret}")
345-
logging.getLogger().debug(f"Downloaded secrets from: {secret}")
346-
return oracledb.connect(user=user, password=password, **creds)

0 commit comments

Comments
 (0)