clickzetta-dbutils 1.0.7__py3-none-any.whl → 1.0.8__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -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"]
@@ -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 _load_connection_configs(cls) -> Dict[str, ConnectionConfig]:
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._load_connection_configs()
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
- def get_connection_infos(self):
98
+ @classmethod
99
+ def get_connection_infos(cls) -> Dict[str, ConnectionConfig]:
99
100
  """
100
101
  Get all connection infos
101
102
  """
102
- return self._load_connection_configs()
103
+ return DatabaseConnectionManager.load_connection_configs()
103
104
 
104
105
  def use_workspace(self, workspace: str) -> 'DatabaseConnectionManager':
105
106
  """
@@ -324,3 +325,57 @@ def get_active_engine(
324
325
  manager.use_driver(driver)
325
326
 
326
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
+ )
@@ -1 +1 @@
1
- __version__ = "1.0.7"
1
+ __version__ = "1.0.8"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: clickzetta-dbutils
3
- Version: 1.0.7
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/
@@ -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=Vv00OcjoBZdC8z1ucEtekEwqPhu95GkgazBdoRBd-bI,10643
3
- clickzetta_dbutils/version.py,sha256=98rTj2jvgnCZhTIeHpbml7e2xuhIqt_9BJNSWkWEQb8,21
4
- clickzetta_dbutils-1.0.7.dist-info/METADATA,sha256=IPehhi4jMgaS7VZfqMhSwTkYkAbnLXHKf708o4537jo,852
5
- clickzetta_dbutils-1.0.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
- clickzetta_dbutils-1.0.7.dist-info/top_level.txt,sha256=8o5KqMSg9pxnPNejHjMaqZV2vEDvwvsz2GdChZI0N6I,19
7
- clickzetta_dbutils-1.0.7.dist-info/RECORD,,