You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Zak Mc Kracken <za...@yahoo.it.INVALID> on 2018/07/24 08:53:02 UTC

Paramterized queries using QueryExecutionFactory and QuerySolutionMap with variable VALUES

Hi all,

apologies if the question was already asked, I cannot find it.

As the subject says, I'd like to parameterise a query like: SELECT ... 
WHERE {  VALUES $rows }

As you can see, the parameter is a list of VALUES tuples, which of 
values I need to take elsewhere and inject here. Normally, I do query 
parameterisation passing a QuerySolutionMap to

QueryExecutionFactory.create ( query, model, initialBinding ), I don't 
use ParameterizedSparqlString when I have to issue the same query many 
times, since I prefer to have better performance by keeping a 
pre-compiled Query object (ParameterizedSparqlString does a mere string 
templating instead).

Question is, is it possible to do the same, when the parameter is as 
complex as the entire list that goes into VALUES?

Thanks in advance for any help.

Marco.



Re: Paramterized queries using QueryExecutionFactory and QuerySolutionMap with variable VALUES

Posted by Zak Mc Kracken <za...@yahoo.it.INVALID>.
Hi Andy,

thank you for your reply. For the moment, I'll do string replacement and 
have enough rows in $rows so that the overhead of re-parsing the query 
is not much, compared to the rest.

Best,
Marco.

On 26/07/2018 11:55, Andy Seaborne wrote:
> Hi Zak,
>
> There's code for replacing a variable in a parsed query 
> (QueryTransformOps) with a value but your example is quite a bit 
> different.  You want to replace "$rows", which is not being used as a 
> variable (it just looks like one!), with a chunk of syntax tree.  
> There isn't anything that does that - it would making it a legal 
> syntax then running a transform over the query to look for 
> VALUES+marker and replacing it with the values.
>
>     Andy
>
> On 24/07/18 09:53, Zak Mc Kracken wrote:
>> Hi all,
>>
>> apologies if the question was already asked, I cannot find it.
>>
>> As the subject says, I'd like to parameterise a query like: SELECT 
>> ... WHERE {  VALUES $rows }
>>
>> As you can see, the parameter is a list of VALUES tuples, which of 
>> values I need to take elsewhere and inject here. Normally, I do query 
>> parameterisation passing a QuerySolutionMap to
>>
>> QueryExecutionFactory.create ( query, model, initialBinding ), I 
>> don't use ParameterizedSparqlString when I have to issue the same 
>> query many times, since I prefer to have better performance by 
>> keeping a pre-compiled Query object (ParameterizedSparqlString does a 
>> mere string templating instead).
>>
>> Question is, is it possible to do the same, when the parameter is as 
>> complex as the entire list that goes into VALUES?
>>
>> Thanks in advance for any help.
>>
>> Marco.
>>
>>


Re: Paramterized queries using QueryExecutionFactory and QuerySolutionMap with variable VALUES

Posted by Andy Seaborne <an...@apache.org>.
Hi Zak,

There's code for replacing a variable in a parsed query 
(QueryTransformOps) with a value but your example is quite a bit 
different.  You want to replace "$rows", which is not being used as a 
variable (it just looks like one!), with a chunk of syntax tree.  There 
isn't anything that does that - it would making it a legal syntax then 
running a transform over the query to look for VALUES+marker and 
replacing it with the values.

     Andy

On 24/07/18 09:53, Zak Mc Kracken wrote:
> Hi all,
> 
> apologies if the question was already asked, I cannot find it.
> 
> As the subject says, I'd like to parameterise a query like: SELECT ... 
> WHERE {  VALUES $rows }
> 
> As you can see, the parameter is a list of VALUES tuples, which of 
> values I need to take elsewhere and inject here. Normally, I do query 
> parameterisation passing a QuerySolutionMap to
> 
> QueryExecutionFactory.create ( query, model, initialBinding ), I don't 
> use ParameterizedSparqlString when I have to issue the same query many 
> times, since I prefer to have better performance by keeping a 
> pre-compiled Query object (ParameterizedSparqlString does a mere string 
> templating instead).
> 
> Question is, is it possible to do the same, when the parameter is as 
> complex as the entire list that goes into VALUES?
> 
> Thanks in advance for any help.
> 
> Marco.
> 
>