Skip to content

Commit a91ca52

Browse files
committed
feat(datatype): support varbyte
1 parent 7b80d75 commit a91ca52

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

redshift_connector/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
TIMETZ,
8585
UNKNOWN,
8686
UUID_TYPE,
87+
VARBYTE,
8788
VARCHAR,
8889
VARCHAR_ARRAY,
8990
XID,

redshift_connector/core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
array_recv_binary,
5959
array_recv_text,
6060
bh_unpack,
61+
bytea_recv,
6162
cccc_unpack,
6263
ci_unpack,
6364
date_in,
@@ -83,6 +84,7 @@
8384
time_recv_binary,
8485
timetz_in,
8586
timetz_recv_binary,
87+
varbytehex_recv,
8688
walk_array,
8789
)
8890
from redshift_connector.utils.type_utils import (
@@ -99,6 +101,7 @@
99101
TIMESTAMP,
100102
TIMESTAMPTZ,
101103
TIMETZ,
104+
VARBYTE,
102105
VARCHAR_ARRAY,
103106
)
104107

@@ -686,6 +689,7 @@ def _enable_protocol_based_conversion_funcs(self: "Connection"):
686689
self.pg_types[REAL_ARRAY] = (FC_BINARY, array_recv_binary) # FLOAT4[]
687690
self.pg_types[1028] = (FC_BINARY, array_recv_binary) # OID[]
688691
self.pg_types[1034] = (FC_BINARY, array_recv_binary) # ACLITEM[]
692+
self.pg_types[VARBYTE] = (FC_TEXT, bytea_recv) # VARBYTE
689693
else: # text protocol
690694
self.pg_types[NUMERIC] = (FC_TEXT, numeric_in)
691695
self.pg_types[TIME] = (FC_TEXT, time_in)
@@ -699,6 +703,7 @@ def _enable_protocol_based_conversion_funcs(self: "Connection"):
699703
self.pg_types[REAL_ARRAY] = (FC_TEXT, float_array_recv) # FLOAT4[]
700704
self.pg_types[1028] = (FC_TEXT, int_array_recv) # OID[]
701705
self.pg_types[1034] = (FC_TEXT, array_recv_text) # ACLITEM[]
706+
self.pg_types[VARBYTE] = (FC_TEXT, varbytehex_recv) # VARBYTE
702707

703708
@property
704709
def _is_multi_databases_catalog_enable_in_server(self: "Connection") -> bool:

redshift_connector/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
array_recv_binary,
1717
array_recv_text,
1818
bh_unpack,
19+
bytea_recv,
1920
cccc_unpack,
2021
ci_unpack,
2122
date_in,
@@ -38,4 +39,5 @@
3839
time_recv_binary,
3940
timetz_in,
4041
timetz_recv_binary,
42+
varbytehex_recv,
4143
)

redshift_connector/utils/type_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import enum
22
import typing
3+
from codecs import decode as codecs_decode
34
from collections import defaultdict
45
from datetime import date
56
from datetime import datetime as Datetime
@@ -90,6 +91,7 @@
9091
UUID_TYPE = 2950
9192
UUID_ARRAY = 2951
9293
VARCHAR = 1043
94+
VARBYTE = 6551
9395
VARCHAR_ARRAY = 1015
9496
XID = 28
9597

@@ -131,8 +133,8 @@ def bool_recv(data: bytes, offset: int, length: int) -> bool:
131133

132134

133135
# bytea
134-
# def bytea_recv(data: bytearray, offset: int, length: int) -> bytearray:
135-
# return data[offset:offset + length]
136+
def bytea_recv(data: bytearray, offset: int, length: int) -> bytearray:
137+
return data[offset : offset + length]
136138

137139

138140
def int8_recv(data: bytes, offset: int, length: int) -> int:
@@ -574,6 +576,10 @@ def geometryhex_recv(data: bytes, idx: int, length: int) -> str:
574576
return result.hex()
575577

576578

579+
def varbytehex_recv(data: bytes, idx: int, length: int) -> bytes:
580+
return codecs_decode(data[idx : idx + length], "hex_codec")
581+
582+
577583
# def inet_in(data: bytes, offset: int, length: int) -> typing.Union[IPv4Address, IPv6Address, IPv4Network, IPv6Network]:
578584
# inet_str: str = data[offset: offset + length].decode(
579585
# _client_encoding)
@@ -634,6 +640,7 @@ def geometryhex_recv(data: bytes, idx: int, length: int) -> str:
634640
GEOMETRYHEX: (FC_TEXT, geometryhex_recv), # GEOMETRYHEX
635641
# 3802: (FC_TEXT, json_in), # jsonb
636642
SUPER: (FC_TEXT, text_recv), # SUPER
643+
VARBYTE: (FC_TEXT, varbytehex_recv), # VARBYTE
637644
},
638645
)
639646

0 commit comments

Comments
 (0)