clickzetta-dbutils 1.0.8__py3-none-any.whl → 1.0.10__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- clickzetta_dbutils/db_utils.py +36 -4
- clickzetta_dbutils/version.py +1 -1
- {clickzetta_dbutils-1.0.8.dist-info → clickzetta_dbutils-1.0.10.dist-info}/METADATA +1 -1
- clickzetta_dbutils-1.0.10.dist-info/RECORD +7 -0
- clickzetta_dbutils-1.0.8.dist-info/RECORD +0 -7
- {clickzetta_dbutils-1.0.8.dist-info → clickzetta_dbutils-1.0.10.dist-info}/WHEEL +0 -0
- {clickzetta_dbutils-1.0.8.dist-info → clickzetta_dbutils-1.0.10.dist-info}/top_level.txt +0 -0
clickzetta_dbutils/db_utils.py
CHANGED
@@ -50,6 +50,7 @@ class DatabaseConnectionManager:
|
|
50
50
|
self._engine: Optional[Engine] = None
|
51
51
|
self._options = {}
|
52
52
|
self._query: Dict[str, str] = {}
|
53
|
+
self._host: Optional[str] = None
|
53
54
|
|
54
55
|
@classmethod
|
55
56
|
def load_connection_configs(cls) -> Dict[str, ConnectionConfig]:
|
@@ -61,10 +62,19 @@ class DatabaseConnectionManager:
|
|
61
62
|
"""
|
62
63
|
if not hasattr(DatabaseConnectionManager, '_connection_cache'):
|
63
64
|
# Retrieve and decode connection info from environment variable
|
64
|
-
conn_info_str =
|
65
|
+
conn_info_str = ""
|
66
|
+
if name := os.environ.get('EXECUTE_LOG_ID', ''):
|
67
|
+
pipe_path = '/tmp/' + name
|
68
|
+
try:
|
69
|
+
pipe_fd = os.open(pipe_path, os.O_RDONLY)
|
70
|
+
with os.fdopen(pipe_fd, 'r') as pipe:
|
71
|
+
conn_info_str = pipe.read()
|
72
|
+
except FileNotFoundError:
|
73
|
+
pass
|
74
|
+
# Fall back to environment variable if pipe is not found
|
75
|
+
conn_info_str = conn_info_str or os.environ.get('connectionInfos', '[]')
|
65
76
|
if not conn_info_str:
|
66
|
-
raise DatabaseConnectionError(
|
67
|
-
"No connection information found in environment variable 'connectionInfos'")
|
77
|
+
raise DatabaseConnectionError("No connection information found in env")
|
68
78
|
decoded_info = urllib.parse.unquote(conn_info_str)
|
69
79
|
conn_list = json.loads(decoded_info)
|
70
80
|
|
@@ -180,6 +190,18 @@ class DatabaseConnectionManager:
|
|
180
190
|
self._query.update(query)
|
181
191
|
return self
|
182
192
|
|
193
|
+
def use_host(self, host: str) -> 'DatabaseConnectionManager':
|
194
|
+
"""
|
195
|
+
Set host for the connection.
|
196
|
+
Args:
|
197
|
+
host (str): Host name
|
198
|
+
Returns:
|
199
|
+
self: For method chaining
|
200
|
+
"""
|
201
|
+
if host:
|
202
|
+
self._host = host
|
203
|
+
return self
|
204
|
+
|
183
205
|
def build(self, *args, **kwargs) -> Engine:
|
184
206
|
"""
|
185
207
|
Create SQLAlchemy engine based on data source name and optional schema
|
@@ -194,7 +216,8 @@ class DatabaseConnectionManager:
|
|
194
216
|
ds_type = conn_info.dsType
|
195
217
|
options = conn_info.options or {}
|
196
218
|
schema = self._schema or conn_info.schema
|
197
|
-
|
219
|
+
host = self._host or conn_info.host
|
220
|
+
host_parts = host.split(':')
|
198
221
|
connect_args = {}
|
199
222
|
|
200
223
|
# Construct connection URL based on data source type
|
@@ -291,6 +314,7 @@ def get_active_engine(
|
|
291
314
|
options: Optional[Dict[str, str]] = None,
|
292
315
|
query: Optional[Dict[str, str]] = None,
|
293
316
|
driver: Optional[str] = None,
|
317
|
+
host: Optional[str] = None,
|
294
318
|
*args, **kwargs
|
295
319
|
) -> Engine:
|
296
320
|
"""
|
@@ -304,6 +328,7 @@ def get_active_engine(
|
|
304
328
|
options (dict, optional): Additional connection options.
|
305
329
|
query (dict, optional): Additional query parameters for SQLAlchemy url.
|
306
330
|
driver (str, optional): Driver name for the connection.
|
331
|
+
host (str, optional): Host name for the connection.
|
307
332
|
*args: Additional arguments for SQLAlchemy engine.
|
308
333
|
|
309
334
|
Returns:
|
@@ -323,6 +348,8 @@ def get_active_engine(
|
|
323
348
|
manager.use_query(query)
|
324
349
|
if driver:
|
325
350
|
manager.use_driver(driver)
|
351
|
+
if host:
|
352
|
+
manager.use_host(host)
|
326
353
|
|
327
354
|
return manager.build(*args, **kwargs)
|
328
355
|
|
@@ -379,3 +406,8 @@ def get_active_lakehouse_engine(
|
|
379
406
|
driver=driver,
|
380
407
|
*args, **kwargs
|
381
408
|
)
|
409
|
+
|
410
|
+
def clean_connection_cache():
|
411
|
+
"""Clear connection cache before each test"""
|
412
|
+
if hasattr(DatabaseConnectionManager, '_connection_cache'):
|
413
|
+
delattr(DatabaseConnectionManager, '_connection_cache')
|
clickzetta_dbutils/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "1.0.
|
1
|
+
__version__ = "1.0.10"
|
@@ -0,0 +1,7 @@
|
|
1
|
+
clickzetta_dbutils/__init__.py,sha256=XSofC7BRKAZbgXkil1HFUiHZztzWWyHcbKNi5tpOjCk,350
|
2
|
+
clickzetta_dbutils/db_utils.py,sha256=Ynn4Gid9uw5WYzRHE_JHTGSdnCaN_JR10Qhv6S18o8U,13827
|
3
|
+
clickzetta_dbutils/version.py,sha256=9EozsBnqDzcKWRDTC1DFubagFbm9pw2hazZ5VjU0tys,22
|
4
|
+
clickzetta_dbutils-1.0.10.dist-info/METADATA,sha256=li7DGwjltrh3uoUQuP6DZ5qYR3dbCD7rTQ31WCVFaxQ,853
|
5
|
+
clickzetta_dbutils-1.0.10.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
6
|
+
clickzetta_dbutils-1.0.10.dist-info/top_level.txt,sha256=8o5KqMSg9pxnPNejHjMaqZV2vEDvwvsz2GdChZI0N6I,19
|
7
|
+
clickzetta_dbutils-1.0.10.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
clickzetta_dbutils/__init__.py,sha256=XSofC7BRKAZbgXkil1HFUiHZztzWWyHcbKNi5tpOjCk,350
|
2
|
-
clickzetta_dbutils/db_utils.py,sha256=AHtyOD-Kk980CtPg6mKIRhW1M7gG9j68-Y7TBJvgF0Q,12681
|
3
|
-
clickzetta_dbutils/version.py,sha256=p_ws-9W7HeP_RfNuGscH3UIczaDFgLeGOeDgRBhdzrc,21
|
4
|
-
clickzetta_dbutils-1.0.8.dist-info/METADATA,sha256=_sO2JXZFTe5AFT0cPa2Uuqz_v-mlRo0qDay1MZ0IOPs,852
|
5
|
-
clickzetta_dbutils-1.0.8.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
6
|
-
clickzetta_dbutils-1.0.8.dist-info/top_level.txt,sha256=8o5KqMSg9pxnPNejHjMaqZV2vEDvwvsz2GdChZI0N6I,19
|
7
|
-
clickzetta_dbutils-1.0.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|