lvaudor / glitter

an R package which writes SPARQL queries
https://lvaudor.github.io/glitter
44 stars 5 forks source link

Time-out #90

Closed spinza closed 1 year ago

spinza commented 1 year ago

Thanks a useful tool.

Is there a way to set time-outs spq_perform? Would be useful to control behaviour for queries that just hang?

maelle commented 1 year ago

Not at the moment, it is not something the user can change. So if you want more flexibility, a short-term solution would be to use glitter for creating the query string but use your own httr2 script to send it. You'd use https://httr2.r-lib.org/reference/req_timeout.html glitter's httr2 code for sending queries is in https://github.com/lvaudor/glitter/blob/7b6460e7e4e3b709d626e43f7793dfb44e221333/R/send_sparql.R#L34 (so you could also work in a fork of glitter and potentially make a PR)

I'll also let the maintainer @lvaudor chime in though. :sweat_smile:

lvaudor commented 1 year ago

Hi! Thanks @spinza for the feedback!

Did you manage to make any progress on that timeout problem? Were you trying to query Wikidata? If so, I think there's not much we can do in terms of setting a timeout ourselves... I believe the way around queries that reach timeout is to split them into multiple, lighter queries. I'm not sure how we could implement that in a generic way though...

However, one way I have tried and done that on some queries was to split them in 2 "processes".

If you wish to query e.g. [?x prop1 ?y] [?y prop2 ?z]

but this query reaches timeout, then you can

1) query [?x prop1 ?y] and then get all values of ?y 2) for each value of ?y (or for several "chunks" of values) query [?y prop2 ?z] (in this part you would use an association of spq_filter/spq_set to set the values of ?y).

Note for future me or future @maelle : maybe it'd be useful to include an example of such a query in the documentation...

spinza commented 1 year ago

Thanks, managed to pull the data I want, but the requests sometimes just get stuck. It would be good to be able to pass a timeout to the send_sparql to pass on to the httr2::request

maelle commented 1 year ago

@spinza in #109 an argument timeout is added to spq_perform() :smile_cat: