Skip to content

Commit da845e6

Browse files
committed
fix(datatype, varbyte): support send and receive hex/text varbyte
1 parent f50db59 commit da845e6

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

redshift_connector/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
array_recv_binary,
5959
array_recv_text,
6060
bh_unpack,
61-
bytea_recv,
6261
cccc_unpack,
6362
ci_unpack,
6463
date_in,
@@ -80,6 +79,7 @@
8079
from redshift_connector.utils import py_types as PY_TYPES
8180
from redshift_connector.utils import (
8281
q_pack,
82+
text_recv,
8383
time_in,
8484
time_recv_binary,
8585
timetz_in,
@@ -689,7 +689,7 @@ def _enable_protocol_based_conversion_funcs(self: "Connection"):
689689
self.pg_types[REAL_ARRAY] = (FC_BINARY, array_recv_binary) # FLOAT4[]
690690
self.pg_types[1028] = (FC_BINARY, array_recv_binary) # OID[]
691691
self.pg_types[1034] = (FC_BINARY, array_recv_binary) # ACLITEM[]
692-
self.pg_types[VARBYTE] = (FC_TEXT, bytea_recv) # VARBYTE
692+
self.pg_types[VARBYTE] = (FC_TEXT, text_recv) # VARBYTE
693693
else: # text protocol
694694
self.pg_types[NUMERIC] = (FC_TEXT, numeric_in)
695695
self.pg_types[TIME] = (FC_TEXT, time_in)

redshift_connector/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
array_recv_binary,
1717
array_recv_text,
1818
bh_unpack,
19-
bytea_recv,
2019
cccc_unpack,
2120
ci_unpack,
2221
date_in,
@@ -35,6 +34,7 @@
3534
pg_types,
3635
py_types,
3736
q_pack,
37+
text_recv,
3838
time_in,
3939
time_recv_binary,
4040
timetz_in,

redshift_connector/utils/type_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def float8_recv(data: bytes, offset: int, length: int) -> float:
173173
return d_unpack(data, offset)[0]
174174

175175

176-
# def bytea_send(v: bytearray) -> bytearray:
177-
# return v
176+
def varbyte_send(v: bytearray) -> bytes:
177+
return v.hex().encode(_client_encoding)
178178

179179

180180
# def uuid_send(v: UUID) -> bytes:
@@ -576,8 +576,8 @@ def geometryhex_recv(data: bytes, idx: int, length: int) -> str:
576576
return result.hex()
577577

578578

579-
def varbytehex_recv(data: bytes, idx: int, length: int) -> bytes:
580-
return codecs_decode(data[idx : idx + length], "hex_codec")
579+
def varbytehex_recv(data: bytes, idx: int, length: int) -> str:
580+
return codecs_decode(data[idx : idx + length], "hex_codec").decode(_client_encoding)
581581

582582

583583
# def inet_in(data: bytes, offset: int, length: int) -> typing.Union[IPv4Address, IPv6Address, IPv4Network, IPv6Network]:
@@ -696,7 +696,7 @@ def numeric_out(d: Decimal) -> bytes:
696696
Decimal: (NUMERIC, FC_TEXT, numeric_out), # Decimal
697697
PGTsvector: (3614, FC_TEXT, text_out),
698698
# UUID: (2950, FC_BINARY, uuid_send), # uuid
699-
# bytes: (17, FC_BINARY, bytea_send), # bytea
699+
bytes: (UNKNOWN, FC_TEXT, varbyte_send), # varbyte
700700
str: (UNKNOWN, FC_TEXT, text_out), # unknown
701701
enum.Enum: (UNKNOWN, FC_TEXT, enum_out),
702702
# IPv4Address: (869, FC_TEXT, inet_out), # inet

0 commit comments

Comments
 (0)