Skip to content

Commit 85d90c9

Browse files
committed
Add codecs for a bunch of new builtin types
The last round of support for esoteric builtin types was quite a while ago, so catch up. Out of non-internal types this adds support for the new `jsonpath` type. Fixes: #635.
1 parent 7c77c33 commit 85d90c9

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

asyncpg/protocol/codecs/pgproto.pyx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ cdef init_json_codecs():
180180
<encode_func>pgproto.jsonb_encode,
181181
<decode_func>pgproto.jsonb_decode,
182182
PG_FORMAT_BINARY)
183+
register_core_codec(JSONPATHOID,
184+
<encode_func>pgproto.jsonpath_encode,
185+
<decode_func>pgproto.jsonpath_decode,
186+
PG_FORMAT_BINARY)
183187

184188

185189
cdef init_int_codecs():
@@ -229,6 +233,17 @@ cdef init_pseudo_codecs():
229233
<decode_func>pgproto.uint4_decode,
230234
PG_FORMAT_BINARY)
231235

236+
# 64-bit OID types
237+
oid8_types = [
238+
XID8OID,
239+
]
240+
241+
for oid_type in oid8_types:
242+
register_core_codec(oid_type,
243+
<encode_func>pgproto.uint8_encode,
244+
<decode_func>pgproto.uint8_decode,
245+
PG_FORMAT_BINARY)
246+
232247
# reg* types -- these are really system catalog OIDs, but
233248
# allow the catalog object name as an input. We could just
234249
# decode these as OIDs, but handling them as text seems more
@@ -237,7 +252,7 @@ cdef init_pseudo_codecs():
237252
reg_types = [
238253
REGPROCOID, REGPROCEDUREOID, REGOPEROID, REGOPERATOROID,
239254
REGCLASSOID, REGTYPEOID, REGCONFIGOID, REGDICTIONARYOID,
240-
REGNAMESPACEOID, REGROLEOID, REFCURSOROID
255+
REGNAMESPACEOID, REGROLEOID, REFCURSOROID, REGCOLLATIONOID,
241256
]
242257

243258
for reg_type in reg_types:
@@ -256,8 +271,10 @@ cdef init_pseudo_codecs():
256271
no_io_types = [
257272
ANYOID, TRIGGEROID, EVENT_TRIGGEROID, LANGUAGE_HANDLEROID,
258273
FDW_HANDLEROID, TSM_HANDLEROID, INTERNALOID, OPAQUEOID,
259-
ANYELEMENTOID, ANYNONARRAYOID, PG_DDL_COMMANDOID,
260-
INDEX_AM_HANDLEROID,
274+
ANYELEMENTOID, ANYNONARRAYOID, ANYCOMPATIBLEOID,
275+
ANYCOMPATIBLEARRAYOID, ANYCOMPATIBLENONARRAYOID,
276+
ANYCOMPATIBLERANGEOID, PG_DDL_COMMANDOID, INDEX_AM_HANDLEROID,
277+
TABLE_AM_HANDLEROID,
261278
]
262279

263280
register_core_codec(ANYENUMOID,
@@ -306,6 +323,13 @@ cdef init_pseudo_codecs():
306323
<decode_func>pgproto.text_decode,
307324
PG_FORMAT_TEXT)
308325

326+
# pg_mcv_list is a special type used in pg_statistic_ext_data
327+
# system catalog
328+
register_core_codec(PG_MCV_LISTOID,
329+
<encode_func>pgproto.bytea_encode,
330+
<decode_func>pgproto.bytea_decode,
331+
PG_FORMAT_BINARY)
332+
309333

310334
cdef init_text_codecs():
311335
textoids = [
@@ -337,8 +361,13 @@ cdef init_tid_codecs():
337361

338362
cdef init_txid_codecs():
339363
register_core_codec(TXID_SNAPSHOTOID,
340-
<encode_func>pgproto.txid_snapshot_encode,
341-
<decode_func>pgproto.txid_snapshot_decode,
364+
<encode_func>pgproto.pg_snapshot_encode,
365+
<decode_func>pgproto.pg_snapshot_decode,
366+
PG_FORMAT_BINARY)
367+
368+
register_core_codec(PG_SNAPSHOTOID,
369+
<encode_func>pgproto.pg_snapshot_encode,
370+
<decode_func>pgproto.pg_snapshot_decode,
342371
PG_FORMAT_BINARY)
343372

344373

asyncpg/protocol/pgtypes.pxi

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
DEF INVALIDOID = 0
1212
DEF MAXBUILTINOID = 9999
13-
DEF MAXSUPPORTEDOID = 4096
13+
DEF MAXSUPPORTEDOID = 5080
1414

1515
DEF BOOLOID = 16
1616
DEF BYTEAOID = 17
@@ -30,6 +30,7 @@ DEF JSONOID = 114
3030
DEF XMLOID = 142
3131
DEF PG_NODE_TREEOID = 194
3232
DEF SMGROID = 210
33+
DEF TABLE_AM_HANDLEROID = 269
3334
DEF INDEX_AM_HANDLEROID = 325
3435
DEF POINTOID = 600
3536
DEF LSEGOID = 601
@@ -96,15 +97,28 @@ DEF REGDICTIONARYOID = 3769
9697
DEF JSONBOID = 3802
9798
DEF ANYRANGEOID = 3831
9899
DEF EVENT_TRIGGEROID = 3838
100+
DEF JSONPATHOID = 4072
99101
DEF REGNAMESPACEOID = 4089
100102
DEF REGROLEOID = 4096
103+
DEF REGCOLLATIONOID = 4191
104+
DEF PG_MCV_LISTOID = 5017
105+
DEF PG_SNAPSHOTOID = 5038
106+
DEF XID8OID = 5069
107+
DEF ANYCOMPATIBLEOID = 5077
108+
DEF ANYCOMPATIBLEARRAYOID = 5078
109+
DEF ANYCOMPATIBLENONARRAYOID = 5079
110+
DEF ANYCOMPATIBLERANGEOID = 5080
101111

102112
cdef ARRAY_TYPES = (_TEXTOID, _OIDOID,)
103113

104114
BUILTIN_TYPE_OID_MAP = {
105115
ABSTIMEOID: 'abstime',
106116
ACLITEMOID: 'aclitem',
107117
ANYARRAYOID: 'anyarray',
118+
ANYCOMPATIBLEARRAYOID: 'anycompatiblearray',
119+
ANYCOMPATIBLENONARRAYOID: 'anycompatiblenonarray',
120+
ANYCOMPATIBLEOID: 'anycompatible',
121+
ANYCOMPATIBLERANGEOID: 'anycompatiblerange',
108122
ANYELEMENTOID: 'anyelement',
109123
ANYENUMOID: 'anyenum',
110124
ANYNONARRAYOID: 'anynonarray',
@@ -135,6 +149,7 @@ BUILTIN_TYPE_OID_MAP = {
135149
INTERVALOID: 'interval',
136150
JSONBOID: 'jsonb',
137151
JSONOID: 'json',
152+
JSONPATHOID: 'jsonpath',
138153
LANGUAGE_HANDLEROID: 'language_handler',
139154
LINEOID: 'line',
140155
LSEGOID: 'lseg',
@@ -149,13 +164,16 @@ BUILTIN_TYPE_OID_MAP = {
149164
PG_DDL_COMMANDOID: 'pg_ddl_command',
150165
PG_DEPENDENCIESOID: 'pg_dependencies',
151166
PG_LSNOID: 'pg_lsn',
167+
PG_MCV_LISTOID: 'pg_mcv_list',
152168
PG_NDISTINCTOID: 'pg_ndistinct',
153169
PG_NODE_TREEOID: 'pg_node_tree',
170+
PG_SNAPSHOTOID: 'pg_snapshot',
154171
POINTOID: 'point',
155172
POLYGONOID: 'polygon',
156173
RECORDOID: 'record',
157174
REFCURSOROID: 'refcursor',
158175
REGCLASSOID: 'regclass',
176+
REGCOLLATIONOID: 'regcollation',
159177
REGCONFIGOID: 'regconfig',
160178
REGDICTIONARYOID: 'regdictionary',
161179
REGNAMESPACEOID: 'regnamespace',
@@ -167,6 +185,7 @@ BUILTIN_TYPE_OID_MAP = {
167185
REGTYPEOID: 'regtype',
168186
RELTIMEOID: 'reltime',
169187
SMGROID: 'smgr',
188+
TABLE_AM_HANDLEROID: 'table_am_handler',
170189
TEXTOID: 'text',
171190
TIDOID: 'tid',
172191
TIMEOID: 'time',
@@ -184,6 +203,7 @@ BUILTIN_TYPE_OID_MAP = {
184203
VARBITOID: 'varbit',
185204
VARCHAROID: 'varchar',
186205
VOIDOID: 'void',
206+
XID8OID: 'xid8',
187207
XIDOID: 'xid',
188208
XMLOID: 'xml',
189209
_OIDOID: 'oid[]',

tests/test_codecs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ def _system_timezone():
271271
'[1, 2, 3, 4]',
272272
'{"a": [1, 2], "b": 0}'
273273
], (9, 4)),
274+
('jsonpath', 'jsonpath', [
275+
'$."track"."segments"[*]."HR"?(@ > 130)',
276+
], (12, 0)),
274277
('oid[]', 'oid[]', [
275278
[1, 2, 3, 4],
276279
[]
@@ -389,6 +392,9 @@ def _system_timezone():
389392
('txid_snapshot', 'txid_snapshot', [
390393
(100, 1000, (100, 200, 300, 400))
391394
]),
395+
('pg_snapshot', 'pg_snapshot', [
396+
(100, 1000, (100, 200, 300, 400))
397+
], (13, 0)),
392398
('varbit', 'varbit', [
393399
asyncpg.BitString('0000 0001'),
394400
asyncpg.BitString('00010001'),

tools/generate_type_map.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@
3333
'real': 'float4',
3434
'double precision': 'float8',
3535
'timestamp with timezone': 'timestamptz',
36+
'timestamp without timezone': 'timestamp',
3637
'time with timezone': 'timetz',
38+
'time without timezone': 'time',
39+
'char': 'bpchar',
40+
'character': 'bpchar',
41+
'character varying': 'varchar',
42+
'bit varying': 'varbit'
3743
}
3844

3945

0 commit comments

Comments
 (0)