Skip to content

Commit 9b8ba99

Browse files
committed
feat(connection): add datashare support, disabled by default
1 parent 17e9cf3 commit 9b8ba99

File tree

6 files changed

+455
-55
lines changed

6 files changed

+455
-55
lines changed

redshift_connector/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def connect(
110110
force_lowercase: bool = False,
111111
allow_db_user_override: bool = False,
112112
client_protocol_version: int = DEFAULT_PROTOCOL_VERSION,
113+
database_metadata_current_db_only: bool = True,
113114
) -> Connection:
114115

115116
info: RedshiftProperty = RedshiftProperty()
@@ -151,6 +152,7 @@ def connect(
151152
force_lowercase=force_lowercase,
152153
allow_db_user_override=allow_db_user_override,
153154
client_protocol_version=client_protocol_version,
155+
database_metadata_current_db_only=database_metadata_current_db_only,
154156
)
155157

156158
return Connection(
@@ -169,6 +171,7 @@ def connect(
169171
application_name=info.application_name,
170172
replication=info.replication,
171173
client_protocol_version=info.client_protocol_version,
174+
database_metadata_current_db_only=database_metadata_current_db_only,
172175
)
173176

174177

redshift_connector/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def get_name(cls, i: int) -> str:
103103
"unicode": "utf-8", # Needed for Amazon Redshift
104104
}
105105

106-
table_type_clauses: dict = {
106+
table_type_clauses: typing.Dict[str, typing.Optional[typing.Dict[str, str]]] = {
107107
"TABLE": {
108108
"SCHEMAS": "c.relkind = 'r' AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'",
109109
"NOSCHEMAS": "c.relkind = 'r' AND c.relname !~ '^pg_'",
@@ -158,4 +158,5 @@ def get_name(cls, i: int) -> str:
158158
"NOSCHEMAS": "c.relkind = 'S' AND c.relname ~ '^pg_temp_' ",
159159
},
160160
"EXTERNAL TABLE": None,
161+
"SHARED TABLE": None,
161162
}

redshift_connector/core.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ def __init__(
364364
application_name: typing.Optional[str] = None,
365365
replication: typing.Optional[str] = None,
366366
client_protocol_version: int = DEFAULT_PROTOCOL_VERSION,
367+
database_metadata_current_db_only: bool = True,
367368
):
368369

369370
self.merge_socket_read = False
@@ -384,6 +385,8 @@ def __init__(
384385
self.max_prepared_statements: int = int(max_prepared_statements)
385386
self._run_cursor: Cursor = Cursor(self, paramstyle="named")
386387
self._client_protocol_version: int = client_protocol_version
388+
self._database = database
389+
self._database_metadata_current_db_only: bool = database_metadata_current_db_only
387390

388391
if user is None:
389392
raise InterfaceError("The 'user' connection parameter cannot be None")
@@ -565,6 +568,18 @@ def __init__(
565568

566569
self.in_transaction = False
567570

571+
@property
572+
def _is_multi_databases_catalog_enable_in_server(self: "Connection") -> bool:
573+
if (b"datashare_enabled", str("on").encode()) in self.parameter_statuses:
574+
return True
575+
else:
576+
# if we don't receive this param from the server, we do not support
577+
return False
578+
579+
@property
580+
def is_single_database_metadata(self):
581+
return self._database_metadata_current_db_only or not self._is_multi_databases_catalog_enable_in_server
582+
568583
def handle_ERROR_RESPONSE(self: "Connection", data, ps):
569584
msg: typing.Dict[str, str] = dict(
570585
(s[:1].decode(_client_encoding), s[1:].decode(_client_encoding)) for s in data.split(NULL_BYTE) if s != b""

0 commit comments

Comments
 (0)