|
25 | 25 |
|
26 | 26 | from sqlalchemy import ( |
27 | 27 | ColumnElement, |
| 28 | + Engine, |
28 | 29 | String, |
29 | 30 | create_engine, |
30 | 31 | delete, |
@@ -126,17 +127,21 @@ class SqlCatalog(MetastoreCatalog): |
126 | 127 | The `SqlCatalog` has a different convention where a `TableIdentifier` requires a `Namespace`. |
127 | 128 | """ |
128 | 129 |
|
129 | | - def __init__(self, name: str, **properties: str): |
| 130 | + def __init__(self, name: str, engine: Engine | None = None, **properties: str): |
130 | 131 | super().__init__(name, **properties) |
131 | 132 |
|
132 | | - if not (uri_prop := self.properties.get(URI)): |
133 | | - raise NoSuchPropertyException("SQL connection URI is required") |
| 133 | + if engine is not None: |
| 134 | + self.engine = engine |
| 135 | + else: |
| 136 | + if not (uri_prop := self.properties.get(URI)): |
| 137 | + raise NoSuchPropertyException("SQL connection URI is required") |
134 | 138 |
|
135 | | - echo_str = str(self.properties.get("echo", DEFAULT_ECHO_VALUE)).lower() |
136 | | - echo = strtobool(echo_str) if echo_str != "debug" else "debug" |
137 | | - pool_pre_ping = strtobool(self.properties.get("pool_pre_ping", DEFAULT_POOL_PRE_PING_VALUE)) |
| 139 | + echo_str = str(self.properties.get("echo", DEFAULT_ECHO_VALUE)).lower() |
| 140 | + echo = strtobool(echo_str) if echo_str != "debug" else "debug" |
| 141 | + pool_pre_ping = strtobool(self.properties.get("pool_pre_ping", DEFAULT_POOL_PRE_PING_VALUE)) |
| 142 | + |
| 143 | + self.engine = create_engine(uri_prop, echo=echo, pool_pre_ping=pool_pre_ping) |
138 | 144 |
|
139 | | - self.engine = create_engine(uri_prop, echo=echo, pool_pre_ping=pool_pre_ping) |
140 | 145 | self._init_catalog() |
141 | 146 |
|
142 | 147 | def _init_catalog(self) -> None: |
|
0 commit comments