-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asyncpg issues a WITH RECURSIVE
query when using float[]
#52
Comments
Hi Marios, thank you for reporting this. The thing is, that asyncpg trips into this code at 1, where Does this sound familiar to you? With kind regards, Footnotes |
I've discovered a few more references here.
This might be a possible solution/workaround? |
When preventing the client to go into the loop processing the elements of
Hope this helps. |
Thanks for investigating! |
Yes, it looks like OID 1021 hasn't been added to the driver yet. In this spirit, I suspect asyncpg will fail in the same way on pgvector as well? -- https://github.com/MagicStack/asyncpg/blob/v0.28.0/asyncpg/protocol/pgtypes.pxi#L52-L56 |
Trying to exercise what is recommended at MagicStack/asyncpg#1078 (comment), both So, effectively, when running such code upfront:
it will emit an SQL statement like: SELECT
t.oid,
t.typelem AS elemtype,
t.typtype AS kind
FROM
pg_catalog.pg_type AS t
INNER JOIN pg_catalog.pg_namespace ns ON (ns.oid = t.typnamespace)
WHERE
t.typname = $1 AND ns.nspname = $2 with arguments:
It will fail with ValueError: unknown type: public.float[] |
All right, after pulling the most recent select typname from pg_catalog.pg_type; I can observe a new type called Now, after adjusting the initialization code accordingly, like: await conn.set_type_codec(
"oidvector",
encoder=lambda s: s,
decoder=lambda s: s,
schema="pg_catalog",
format="binary") asyncpg will use those arguments on the SQL statement outlined in my previous post: ['oidvector', 'pg_catalog'] and will fail with a different exception: File "/Users/amo/dev/crate/drivers/asyncpg/test_cratedb.py", line 120, in exec_queries_pooled
await conn.set_type_codec(
File "/Users/amo/dev/crate/drivers/asyncpg/asyncpg/connection.py", line 1252, in set_type_codec
raise exceptions.InterfaceError(
asyncpg.exceptions._base.InterfaceError: cannot use custom codec on type pg_catalog.oidvector: it is neither a scalar type nor a composite type |
When using the other type of type registry helper function, await conn.set_builtin_type_codec(
"oidvector",
schema="pg_catalog",
codec_name="binary",
) the exception is like: File "/Users/amo/dev/crate/drivers/asyncpg/test_cratedb.py", line 129, in exec_queries_pooled
await conn.set_builtin_type_codec(
File "/Users/amo/dev/crate/drivers/asyncpg/asyncpg/connection.py", line 1332, in set_builtin_type_codec
raise exceptions.InterfaceError(
asyncpg.exceptions._base.InterfaceError: cannot alias non-scalar type pg_catalog.oidvector |
|
Now that the introspection query works, by using a snippet like await conn.set_type_codec(
"oidvector",
encoder=lambda s: s,
decoder=lambda s: s,
schema="pg_catalog",
) yielding an SQL of: SELECT
t.oid,
t.typelem AS elemtype,
t.typtype AS kind
FROM
pg_catalog.pg_type AS t
INNER JOIN pg_catalog.pg_namespace ns ON (ns.oid = t.typnamespace)
WHERE
t.typname = 'oidvector' AND ns.nspname = 'pg_catalog'
; and a result of:
we can inspect what goes wrong. Internally, asyngpc wraps that into:
Please note that |
Now, I would like to guide you to the implementation where the exception from asyncpg is originating from, see 1. Oh, that has been improved already (I am on Nevertheless, this is why it can't be classified as "scalar type":
If it should be classified as "composite type", it would need to satisfy Footnotes |
Thank you. Unfortunately, I can't spot such a type when running this SQL statement. select typname, typelem AS elemtype, typtype AS kind from pg_catalog.pg_type; Does it miss to list a corresponding item like?
|
I was able to register something with vector_type = dict(
oid=1021,
ns="pg_catalog",
name="float[]",
kind=b"b",
basetype=0,
elemtype=26,
elemdelim=",",
range_subtype=None,
attrtypoids=None,
)
settings = conn._protocol.get_settings()
settings.register_data_types([vector_type]) Most probably, I made many mistakes, that's why the results of the
|
Using Type Definitionvector_type = dict(
oid=1021,
ns="pg_catalog",
name="float[]",
kind=b"b",
basetype=0,
elemtype=700,
elemdelim=",",
range_subtype=None,
attrtypoids=None,
) Outcome
|
Thx a lot for your work here! at least we have some kind of workaround if users ask for it. |
I'd say to leave this issue open for the time being and I'll raise a discussion for maybe implementing |
Thanks. What about adding the missing type definition to the corresponding table in CrateDB's pg_catalog?
On 25 September 2023 17:25:54 CEST, Marios Trivyzas ***@***.***> wrote:
I'd say to leave this issue open for the time being and I'll raise a discussion for maybe implementing `WITH RECURSIVE` soon.
--
Reply to this email directly or view it on GitHub:
#52 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
--
Sent from my mind. This might have been typed on a mobile device, so please excuse my brevity.
|
|
Aha, all right. Does it make sense then to ask at asyncpg about adding support for OID 1021?
On 25 September 2023 19:12:04 CEST, Marios Trivyzas ***@***.***> wrote:
`float[]` is already registered in `pg_type` for CrateDB (it's `_float4`, `_` prefix denotes `array of`)
--
Reply to this email directly or view it on GitHub:
#52 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
--
Sent from my mind. This might have been typed on a mobile device, so please excuse my brevity.
|
I think yes, because all arrays have the same issue and the
|
Lets document the required steps for a user to use the |
Just to chime in, I'm seeing 14 second queries with CockroachDB doing this inspection for _varchar |
sorry, just realized this isn't the right repo for this. |
I've tried to introduce a
float[]
test: https://gist.github.com/matriv/05bec849ff166789d0378625e43c06b0 in: https://github.com/crate/crate-qa/blob/master/tests/client_tests/python/asyncpg/test_asyncpg.py(method in question:
float_vector_can_be_inserted_and_selected
)and the driver issues the following query which currently CrateDB doesn't support (
WITH RECURSIVE
)Maybe there is a way to avoid this query by tweaking asyncpg?
The text was updated successfully, but these errors were encountered: