Skip to content

Commit c9697f1

Browse files
rueiyhuangtimm4205
authored andcommitted
feat!: Removed unsupported COPY/UNLOAD feature implementation
1 parent 6f71969 commit c9697f1

File tree

2 files changed

+1
-166
lines changed

2 files changed

+1
-166
lines changed

redshift_connector/core.py

Lines changed: 1 addition & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,6 @@ def make_args(vals):
307307
NO_DATA: bytes = b"n"
308308
PARAMETER_DESCRIPTION: bytes = b"t"
309309
NOTIFICATION_RESPONSE: bytes = b"A"
310-
COPY_DONE: bytes = b"c"
311-
COPY_DATA: bytes = b"d"
312-
COPY_IN_RESPONSE: bytes = b"G"
313-
COPY_OUT_RESPONSE: bytes = b"H"
314310
EMPTY_QUERY_RESPONSE: bytes = b"I"
315311

316312
BIND: bytes = b"B"
@@ -335,7 +331,6 @@ def create_message(code: bytes, data: bytes = b"") -> bytes:
335331
FLUSH_MSG: bytes = create_message(FLUSH)
336332
SYNC_MSG: bytes = create_message(SYNC)
337333
TERMINATE_MSG: bytes = create_message(TERMINATE)
338-
COPY_DONE_MSG: bytes = create_message(COPY_DONE)
339334
EXECUTE_MSG: bytes = create_message(EXECUTE, NULL_BYTE + i_pack(0))
340335

341336
# DESCRIBE constants
@@ -766,10 +761,6 @@ def get_calling_module() -> str:
766761
NO_DATA: self.handle_NO_DATA,
767762
PARAMETER_DESCRIPTION: self.handle_PARAMETER_DESCRIPTION,
768763
NOTIFICATION_RESPONSE: self.handle_NOTIFICATION_RESPONSE,
769-
COPY_DONE: self.handle_COPY_DONE,
770-
COPY_DATA: self.handle_COPY_DATA,
771-
COPY_IN_RESPONSE: self.handle_COPY_IN_RESPONSE,
772-
COPY_OUT_RESPONSE: self.handle_COPY_OUT_RESPONSE,
773764
}
774765

775766
# Int32 - Message length, including self.
@@ -1139,155 +1130,6 @@ def handle_PARAMETER_DESCRIPTION(self: "Connection", data, ps):
11391130
# type_oids = unpack_from("!" + "i" * count, data, 2)
11401131
_logger.debug("ParameterDescription received from BE")
11411132

1142-
def handle_COPY_DONE(self: "Connection", data, ps):
1143-
"""
1144-
Handler for CopyDone message received via Amazon Redshift wire protocol, represented by b'c' code.
1145-
1146-
CopyDone (F & B)
1147-
Byte1('c')
1148-
Identifies the message as a COPY-complete indicator.
1149-
1150-
Int32(4)
1151-
Length of message contents in bytes, including self.
1152-
1153-
Parameters
1154-
----------
1155-
:param data: bytes:
1156-
Message content
1157-
:param ps: typing.Optional[typing.Dict[str, typing.Any]]:
1158-
Prepared Statement from associated Cursor
1159-
1160-
Returns
1161-
-------
1162-
None:None
1163-
"""
1164-
_logger.debug("CopyDone received from BE")
1165-
self._copy_done = True
1166-
1167-
def handle_COPY_OUT_RESPONSE(self: "Connection", data, ps):
1168-
"""
1169-
Handler for CopyOutResponse message received via Amazon Redshift wire protocol, represented by b'H' code.
1170-
1171-
CopyOutResponse (B)
1172-
Byte1('H')
1173-
Identifies the message as a Start Copy Out response. This message will be followed by copy-out data.
1174-
1175-
Int32
1176-
Length of message contents in bytes, including self.
1177-
1178-
Int8
1179-
0 indicates the overall COPY format is textual (rows separated by newlines, columns separated by separator characters, etc). 1 indicates the overall copy format is binary (similar to DataRow format). See COPY for more information.
1180-
1181-
Int16
1182-
The number of columns in the data to be copied (denoted N below).
1183-
1184-
Int16[N]
1185-
The format codes to be used for each column. Each must presently be zero (text) or one (binary). All must be zero if the overall copy format is textual.
1186-
1187-
Parameters
1188-
----------
1189-
:param data: bytes:
1190-
Message content
1191-
:param ps: typing.Optional[typing.Dict[str, typing.Any]]:
1192-
Prepared Statement from associated Cursor
1193-
1194-
Returns
1195-
-------
1196-
None:None
1197-
"""
1198-
_logger.debug("CopyOutResponse received from BE")
1199-
is_binary, num_cols = bh_unpack(data)
1200-
_logger.debug("isbinary=%s num_cols=%s", is_binary, num_cols)
1201-
# column_formats = unpack_from('!' + 'h' * num_cols, data, 3)
1202-
if ps.stream is None:
1203-
raise InterfaceError("An output stream is required for the COPY OUT response.")
1204-
1205-
def handle_COPY_DATA(self: "Connection", data, ps) -> None:
1206-
"""
1207-
Handler for CopyData message received via Amazon Redshift wire protocol, represented by b'd' code.
1208-
1209-
CopyData (F & B)
1210-
Byte1('d')
1211-
Identifies the message as COPY data.
1212-
1213-
Int32
1214-
Length of message contents in bytes, including self.
1215-
1216-
Byten
1217-
Data that forms part of a COPY data stream. Messages sent from the backend will always correspond to single data rows, but messages sent by frontends may divide the data stream arbitrarily.
1218-
1219-
Parameters
1220-
----------
1221-
:param data: bytes:
1222-
Message content
1223-
:param ps: typing.Optional[typing.Dict[str, typing.Any]]:
1224-
Prepared Statement from associated Cursor
1225-
1226-
Returns
1227-
-------
1228-
None:None
1229-
"""
1230-
_logger.debug("CopyData received from BE")
1231-
ps.stream.write(data)
1232-
1233-
def handle_COPY_IN_RESPONSE(self: "Connection", data, ps):
1234-
"""
1235-
Handler for CopyInResponse message received via Amazon Redshift wire protocol, represented by b'G' code.
1236-
1237-
CopyInResponse (B)
1238-
Byte1('G')
1239-
Identifies the message as a Start Copy In response. The frontend must now send copy-in data (if not prepared to do so, send a CopyFail message).
1240-
1241-
Int32
1242-
Length of message contents in bytes, including self.
1243-
1244-
Int8
1245-
0 indicates the overall COPY format is textual (rows separated by newlines, columns separated by separator characters, etc). 1 indicates the overall copy format is binary (similar to DataRow format). See COPY for more information.
1246-
1247-
Int16
1248-
The number of columns in the data to be copied (denoted N below).
1249-
1250-
Int16[N]
1251-
The format codes to be used for each column. Each must presently be zero (text) or one (binary). All must be zero if the overall copy format is textual.
1252-
1253-
Parameters
1254-
----------
1255-
:param data: bytes:
1256-
Message content
1257-
:param ps: typing.Optional[typing.Dict[str, typing.Any]]:
1258-
Prepared Statement from associated Cursor
1259-
1260-
Returns
1261-
-------
1262-
None:None
1263-
"""
1264-
_logger.debug("CopyInResponse received from BE")
1265-
# Int16(2) - Number of columns
1266-
# Int16(N) - Format codes for each column (0 text, 1 binary)
1267-
is_binary, num_cols = bh_unpack(data)
1268-
_logger.debug("isbinary=%s num_cols=%s", (is_binary, num_cols))
1269-
# column_formats = unpack_from('!' + 'h' * num_cols, data, 3)
1270-
if ps.stream is None:
1271-
raise InterfaceError("An input stream is required for the COPY IN response.")
1272-
1273-
bffr: bytearray = bytearray(8192)
1274-
while True:
1275-
bytes_read = ps.stream.readinto(bffr)
1276-
if bytes_read == 0:
1277-
break
1278-
self._write(COPY_DATA + i_pack(bytes_read + 4))
1279-
self._write(bffr[:bytes_read])
1280-
self._flush()
1281-
1282-
# Send CopyDone
1283-
# Byte1('c') - Identifier.
1284-
# Int32(4) - Message length, including self.
1285-
_logger.debug("Sending CopyDone message to BE")
1286-
self._write(COPY_DONE_MSG)
1287-
_logger.debug("Sending Sync message to BE")
1288-
self._write(SYNC_MSG)
1289-
self._flush()
1290-
12911133
def handle_NOTIFICATION_RESPONSE(self: "Connection", data, ps):
12921134
"""
12931135
Handler for NotificationResponse message received via Amazon Redshift wire protocol, represented by
@@ -2707,4 +2549,4 @@ def get_max_prepared_statement(self, max_prepared_statements: int) -> int:
27072549
if max_prepared_statements < 0:
27082550
_logger.error("Parameter max_prepared_statements must >= 0. Using default value %d", DEFAULT_MAX_PREPARED_STATEMENTS)
27092551
return DEFAULT_MAX_PREPARED_STATEMENTS
2710-
return max_prepared_statements
2552+
return max_prepared_statements

test/unit/test_connection.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,6 @@ def test_handle_error_response(_input) -> None:
142142
assert str(expected_decoded_msg) in str(mock_connection.error)
143143

144144

145-
def test_handle_copy_done() -> None:
146-
mock_connection = Connection.__new__(Connection)
147-
assert hasattr(mock_connection, "_copy_done") is False
148-
mock_connection.handle_COPY_DONE(None, None)
149-
assert mock_connection._copy_done is True
150-
151-
152145
test_inspect_int_vals: typing.List[typing.Tuple[int, typing.Tuple[int, int, typing.Callable]]] = [
153146
(min_int2 - 1, PY_TYPES[23]),
154147
(min_int2, PY_TYPES[23]),

0 commit comments

Comments
 (0)