clickzetta-dbutils 1.0.6__py3-none-any.whl → 1.0.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clickzetta_dbutils/__init__.py +2 -2
- clickzetta_dbutils/db_utils.py +70 -5
- clickzetta_dbutils/version.py +1 -1
- {clickzetta_dbutils-1.0.6.dist-info → clickzetta_dbutils-1.0.8.dist-info}/METADATA +5 -3
- clickzetta_dbutils-1.0.8.dist-info/RECORD +7 -0
- clickzetta_dbutils-1.0.6.dist-info/RECORD +0 -7
- {clickzetta_dbutils-1.0.6.dist-info → clickzetta_dbutils-1.0.8.dist-info}/WHEEL +0 -0
- {clickzetta_dbutils-1.0.6.dist-info → clickzetta_dbutils-1.0.8.dist-info}/top_level.txt +0 -0
clickzetta_dbutils/__init__.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from .db_utils import get_active_engine, get_lakehouse_connection, DatabaseConnectionManager, ConnectionConfig, \
|
2
|
-
DatabaseConnectionError
|
2
|
+
DatabaseConnectionError, get_active_lakehouse_engine
|
3
3
|
|
4
|
-
__all__ = ["get_active_engine", "get_lakehouse_connection", "DatabaseConnectionManager", "ConnectionConfig",
|
4
|
+
__all__ = ["get_active_engine", "get_lakehouse_connection", "get_active_lakehouse_engine", "DatabaseConnectionManager", "ConnectionConfig",
|
5
5
|
"DatabaseConnectionError"]
|
clickzetta_dbutils/db_utils.py
CHANGED
@@ -38,7 +38,7 @@ class DatabaseConnectionManager:
|
|
38
38
|
Manages database connections with flexible configuration options.
|
39
39
|
"""
|
40
40
|
|
41
|
-
def __init__(self, ds_name: str):
|
41
|
+
def __init__(self, ds_name: Optional[str] = None):
|
42
42
|
"""
|
43
43
|
Initialize a database connection for a specific data source.
|
44
44
|
"""
|
@@ -52,7 +52,7 @@ class DatabaseConnectionManager:
|
|
52
52
|
self._query: Dict[str, str] = {}
|
53
53
|
|
54
54
|
@classmethod
|
55
|
-
def
|
55
|
+
def load_connection_configs(cls) -> Dict[str, ConnectionConfig]:
|
56
56
|
"""
|
57
57
|
Load and cache connection configurations from environment variables.
|
58
58
|
|
@@ -83,7 +83,7 @@ class DatabaseConnectionManager:
|
|
83
83
|
"""
|
84
84
|
Find connection info by data source name
|
85
85
|
"""
|
86
|
-
connections = self.
|
86
|
+
connections = self.load_connection_configs()
|
87
87
|
|
88
88
|
# Validate data source exists
|
89
89
|
if ds_name not in connections:
|
@@ -95,11 +95,12 @@ class DatabaseConnectionManager:
|
|
95
95
|
config.query.update(self._query)
|
96
96
|
return config
|
97
97
|
|
98
|
-
|
98
|
+
@classmethod
|
99
|
+
def get_connection_infos(cls) -> Dict[str, ConnectionConfig]:
|
99
100
|
"""
|
100
101
|
Get all connection infos
|
101
102
|
"""
|
102
|
-
return
|
103
|
+
return DatabaseConnectionManager.load_connection_configs()
|
103
104
|
|
104
105
|
def use_workspace(self, workspace: str) -> 'DatabaseConnectionManager':
|
105
106
|
"""
|
@@ -255,6 +256,7 @@ class DatabaseConnectionManager:
|
|
255
256
|
query=query_params
|
256
257
|
)
|
257
258
|
elif conn_info.magicToken:
|
259
|
+
# Use magic token for authentication, do not require username and password
|
258
260
|
query_params["magic_token"] = conn_info.magicToken
|
259
261
|
url = URL.create(
|
260
262
|
drivername="clickzetta",
|
@@ -287,6 +289,8 @@ def get_active_engine(
|
|
287
289
|
workspace: Optional[str] = None,
|
288
290
|
schema: Optional[str] = None,
|
289
291
|
options: Optional[Dict[str, str]] = None,
|
292
|
+
query: Optional[Dict[str, str]] = None,
|
293
|
+
driver: Optional[str] = None,
|
290
294
|
*args, **kwargs
|
291
295
|
) -> Engine:
|
292
296
|
"""
|
@@ -298,6 +302,9 @@ def get_active_engine(
|
|
298
302
|
workspace (str, optional): Workspace name. Default is 'default'.
|
299
303
|
schema (str, optional): Schema name for the connection. Default is 'public'.
|
300
304
|
options (dict, optional): Additional connection options.
|
305
|
+
query (dict, optional): Additional query parameters for SQLAlchemy url.
|
306
|
+
driver (str, optional): Driver name for the connection.
|
307
|
+
*args: Additional arguments for SQLAlchemy engine.
|
301
308
|
|
302
309
|
Returns:
|
303
310
|
SQLAlchemy Engine instance
|
@@ -312,5 +319,63 @@ def get_active_engine(
|
|
312
319
|
manager.use_vcluster(vcluster)
|
313
320
|
if options:
|
314
321
|
manager.use_options(options)
|
322
|
+
if query:
|
323
|
+
manager.use_query(query)
|
324
|
+
if driver:
|
325
|
+
manager.use_driver(driver)
|
315
326
|
|
316
327
|
return manager.build(*args, **kwargs)
|
328
|
+
|
329
|
+
|
330
|
+
def get_active_lakehouse_engine(
|
331
|
+
vcluster: Optional[str] = None,
|
332
|
+
workspace: Optional[str] = None,
|
333
|
+
schema: Optional[str] = None,
|
334
|
+
options: Optional[Dict[str, str]] = None,
|
335
|
+
query: Optional[Dict[str, str]] = None,
|
336
|
+
driver: Optional[str] = None,
|
337
|
+
*args, **kwargs
|
338
|
+
) -> Engine:
|
339
|
+
"""
|
340
|
+
Convenience function to create a database engine for lakehouse (ClickZetta) data source.
|
341
|
+
|
342
|
+
Args:
|
343
|
+
vcluster (str, optional): Virtual cluster name for ClickZetta data source. Required.
|
344
|
+
workspace (str, optional): Workspace name. Default is 'default'.
|
345
|
+
schema (str, optional): Schema name for the connection. Default is 'public'.
|
346
|
+
options (dict, optional): Additional connection options.
|
347
|
+
query (dict, optional): Additional query parameters for SQLAlchemy url.
|
348
|
+
driver (str, optional): Driver name for the connection.
|
349
|
+
*args: Additional arguments for SQLAlchemy engine.
|
350
|
+
**kwargs: Additional keyword arguments for SQLAlchemy engine.
|
351
|
+
|
352
|
+
Returns:
|
353
|
+
SQLAlchemy Engine instance
|
354
|
+
|
355
|
+
Raises:
|
356
|
+
DatabaseConnectionError: If no lakehouse data source is found in the configuration.
|
357
|
+
"""
|
358
|
+
# Get all connection configurations
|
359
|
+
conn_infos = DatabaseConnectionManager.get_connection_infos()
|
360
|
+
|
361
|
+
# Find the lakehouse (ClickZetta) data source
|
362
|
+
lakehouse_ds = None
|
363
|
+
for ds_name, conn_info in conn_infos.items():
|
364
|
+
if conn_info.dsType == 1: # ClickZetta type
|
365
|
+
lakehouse_ds = ds_name
|
366
|
+
break
|
367
|
+
|
368
|
+
if not lakehouse_ds:
|
369
|
+
raise DatabaseConnectionError("No lakehouse (ClickZetta) data source found in configuration")
|
370
|
+
|
371
|
+
# Create engine using the found lakehouse data source
|
372
|
+
return get_active_engine(
|
373
|
+
ds_name=lakehouse_ds,
|
374
|
+
vcluster=vcluster,
|
375
|
+
workspace=workspace,
|
376
|
+
schema=schema,
|
377
|
+
options=options,
|
378
|
+
query=query,
|
379
|
+
driver=driver,
|
380
|
+
*args, **kwargs
|
381
|
+
)
|
clickzetta_dbutils/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "1.0.
|
1
|
+
__version__ = "1.0.8"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: clickzetta-dbutils
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.8
|
4
4
|
Summary: clickzetta dbutils
|
5
5
|
Author-email: "lin.zhang" <lin.zhang@clickzetta.com>
|
6
6
|
Project-URL: documentation, https://www.yunqi.tech/
|
@@ -16,6 +16,8 @@ Provides-Extra: dev
|
|
16
16
|
Requires-Dist: pytest==8.2.1; extra == "dev"
|
17
17
|
Requires-Dist: build; extra == "dev"
|
18
18
|
Requires-Dist: pytest-xdist; extra == "dev"
|
19
|
+
Provides-Extra: cliclzetta-legecy-sdk
|
20
|
+
Requires-Dist: clickzetta-connector; extra == "cliclzetta-legecy-sdk"
|
21
|
+
Requires-Dist: clickzetta-sqlalchemy; extra == "cliclzetta-legecy-sdk"
|
19
22
|
Provides-Extra: cliclzetta
|
20
|
-
Requires-Dist: clickzetta-connector; extra == "cliclzetta"
|
21
|
-
Requires-Dist: clickzetta-sqlalchemy; extra == "cliclzetta"
|
23
|
+
Requires-Dist: clickzetta-connector-python; extra == "cliclzetta"
|
@@ -0,0 +1,7 @@
|
|
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,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
clickzetta_dbutils/__init__.py,sha256=Q_6kas0RvZ0767qlaA_xGESmXxm0dks1YQ8DqCX8LV0,290
|
2
|
-
clickzetta_dbutils/db_utils.py,sha256=1iVaiYIQosukrQBAbgjNXJJW51p7k1ihQKBIcl_MvQM,10166
|
3
|
-
clickzetta_dbutils/version.py,sha256=fCDDAyG3nMZcE_hvt1RHdxkiFN3DfNSyU_k-rLUDrpE,21
|
4
|
-
clickzetta_dbutils-1.0.6.dist-info/METADATA,sha256=mpfK67NkOGCBN_wu5NcTvMLLTsVGlLxmnNdcX3KTiFw,726
|
5
|
-
clickzetta_dbutils-1.0.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
6
|
-
clickzetta_dbutils-1.0.6.dist-info/top_level.txt,sha256=8o5KqMSg9pxnPNejHjMaqZV2vEDvwvsz2GdChZI0N6I,19
|
7
|
-
clickzetta_dbutils-1.0.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|