-
Notifications
You must be signed in to change notification settings - Fork 6
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
Query objects are not supported as input to the query method #26
Comments
Thank you for this nice bug report! I have fixed the condition in 85ce7d4 and released v0.3.4 with the fix.
Yes, indeed. Not sure about the speed up because there is the conversion cost between Python and Rust and I am not sure if it's much faster than SPARQL parsing. I see two ways of implementing this:
Approach 2 might be slightly slower but might be easier to implement and having a serializer for SPARQL algebra objects might be a relevant feature for rdflib independently of Oxigraph. |
Some food for thought: Rdflib is often perceived as rather slow. I think that the main reasons for this are either: For the project I am working on I first switched to the Oxigraph store because of a hint on Stack Overflow (https://stackoverflow.com/a/71008345). I was really surprised by how much faster my program ran. I can imagine that quite some people are using Query objects instead of SPARQL strings just for performance reasons. While a serialization from rdflib Query objects to SPARQL strings might not be very costly computationally, the generation of the rdflib Query objects (e.g. using the rdflib.plugins.sparql.prepareQuery function) in the first place is computationally expensive. So maybe instead of going with approach 2 it might even be more sensible to not change anything and rather educate people to use only SPARQL strings and to not even prepare Query objects when using the Oxigraph store. Side note: How efficient is the creation of Rust spargebra objects from SPARQL strings? Maybe it makes sense to cache/memoize this somehow in Oxigraph? |
I ran into a similar problem ages ago, and I submitted a PR with a "temporary" patch, which apparently is still there 😆 : a I monkeypatched if isinstance(query, rdflib.plugins.sparql.sparql.Query) and hasattr(query, "_original_args"):
query, initInitNs, base = query._original_args
initInitNs.update(initNs)
initNs = initInitNs
if base:
kwargs.setdefault('base', base)
base = kwargs.pop('base', None)
if base != None:
query = f'BASE <{base}>\n{query}' |
@pchampin Nice! Thank you! I am a bit reluctant to use it in oxrdflib. I guess that if the |
I would never have considered mutating an instance of Query, but it is true that the attributes are apparently "public" (per the naming convention), so in principle "open for mutation"... but I would consider that (mutating the attribute of a Query instance) as a footgun... Would you be more comfortable to apply the strategy above if all attributes of Query were "protected" in RDFlib? If so, it might be worth asking what the intention of the authors are, and proposing a patch. |
The query method of the
OxigraphStore
does not accept rdflibQuery
objects but only strings and otherwise fails with aTypeError
.Example:
Maybe the line
oxrdflib/oxrdflib/__init__.py
Line 110 in b8008f2
if isinstance(query, Query) or kwargs
for the time being?In the long term, it would be great if prepared
Query
objects could be supported. Maybe this could result in even further speed ups? Probably this is related to #11 as well.Thanks a lot for your efforts!
The text was updated successfully, but these errors were encountered: