You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Zen 98052 <z9...@outlook.com> on 2015/09/16 17:19:30 UTC

paging the query results

Any idea on how to do the paging on the results set?

For example in this code:


ResultSet rs = qe.execSelect();


I was thinking to use com.google.common.collect.FluentIterable, so let say I have the start offset and rows count values.

To do the paging logic in naive way would be something like:


FluentIterable<QuerySolution> newIterator = FluentIterable.from(rs);

newIterator.skip(startOffset);

newIterator.limit(rowsCount);


Unfortunately the first line doesn't work (the ResultSet type is not type of Iterable as expected by FluentIterable).

Let me know the right way of paging the query results.



Thanks,

Z

Re: paging the query results

Posted by Zen 98052 <z9...@outlook.com>.
Thanks A. Soroka and Andy!

@Andy: is it possible to control the data from query engine/server side without need to change the SPARQL query?
I am thinking to pass the start offset and rows count values to query execution context, and 'somewhere' in that query engine will read those values from the execution context and limit the data.
With this, the caller/client could send the same SPARQL query, and pass the start offset and rows count info separately (i.e. via URL query string to my own Sparql web interface)
I don't know where is that 'somewhere', but this seems possible from Jena, right?

Thanks,
Z

________________________________________
From: ajs6f@virginia.edu <aj...@virginia.edu>
Sent: Wednesday, September 16, 2015 12:08 PM
To: users@jena.apache.org
Subject: Re: paging the query results

For the record,

https://stackoverflow.com/questions/28210775/split-list-into-multiple-lists-with-fixed-number-of-elements-in-java-8/28211518

is a better answer than the one I first linked.

---
A. Soroka
The University of Virginia Library

> On Sep 16, 2015, at 12:02 PM, Andy Seaborne <an...@apache.org> wrote:
>
> Yes - A ResultSet isn't Iterable because you can only read it once unless you do something like ResultSetFactory.makeRewindable,
> Hence converting to a stream (.sequential() if ordered!)) is nice.
>
> If you are throwing away the part of the results outside the startOffset/rowsCount slice, you can add OFFSET & LIMIT to the query then the query engine/server can do it, resulting in less bytes.
>
> If you want the client to control it, the streams way is good.
>
>       Andy
>
> On 16/09/15 16:27, ajs6f@virginia.edu wrote:
>> One option: Jena is now using Java 8, so you can use the Streams API to do this:
>>
>> https://stackoverflow.com/questions/29273705/how-to-paginate-a-list-of-objects-in-java-8
>>
>> ResultSet is an Iterator, so you can convert it to a Stream.
>>
>> ---
>> A. Soroka
>> The University of Virginia Library
>>
>>> On Sep 16, 2015, at 11:19 AM, Zen 98052 <z9...@outlook.com> wrote:
>>>
>>> Any idea on how to do the paging on the results set?
>>>
>>> For example in this code:
>>>
>>>
>>> ResultSet rs = qe.execSelect();
>>>
>>>
>>> I was thinking to use com.google.common.collect.FluentIterable, so let say I have the start offset and rows count values.
>>>
>>> To do the paging logic in naive way would be something like:
>>>
>>>
>>> FluentIterable<QuerySolution> newIterator = FluentIterable.from(rs);
>>>
>>> newIterator.skip(startOffset);
>>>
>>> newIterator.limit(rowsCount);
>>>
>>>
>>> Unfortunately the first line doesn't work (the ResultSet type is not type of Iterable as expected by FluentIterable).
>>>
>>> Let me know the right way of paging the query results.
>>>
>>>
>>>
>>> Thanks,
>>>
>>> Z
>>
>


Re: paging the query results

Posted by "ajs6f@virginia.edu" <aj...@virginia.edu>.
For the record,

https://stackoverflow.com/questions/28210775/split-list-into-multiple-lists-with-fixed-number-of-elements-in-java-8/28211518

is a better answer than the one I first linked.

---
A. Soroka
The University of Virginia Library

> On Sep 16, 2015, at 12:02 PM, Andy Seaborne <an...@apache.org> wrote:
> 
> Yes - A ResultSet isn't Iterable because you can only read it once unless you do something like ResultSetFactory.makeRewindable,
> Hence converting to a stream (.sequential() if ordered!)) is nice.
> 
> If you are throwing away the part of the results outside the startOffset/rowsCount slice, you can add OFFSET & LIMIT to the query then the query engine/server can do it, resulting in less bytes.
> 
> If you want the client to control it, the streams way is good.
> 
> 	Andy
> 
> On 16/09/15 16:27, ajs6f@virginia.edu wrote:
>> One option: Jena is now using Java 8, so you can use the Streams API to do this:
>> 
>> https://stackoverflow.com/questions/29273705/how-to-paginate-a-list-of-objects-in-java-8
>> 
>> ResultSet is an Iterator, so you can convert it to a Stream.
>> 
>> ---
>> A. Soroka
>> The University of Virginia Library
>> 
>>> On Sep 16, 2015, at 11:19 AM, Zen 98052 <z9...@outlook.com> wrote:
>>> 
>>> Any idea on how to do the paging on the results set?
>>> 
>>> For example in this code:
>>> 
>>> 
>>> ResultSet rs = qe.execSelect();
>>> 
>>> 
>>> I was thinking to use com.google.common.collect.FluentIterable, so let say I have the start offset and rows count values.
>>> 
>>> To do the paging logic in naive way would be something like:
>>> 
>>> 
>>> FluentIterable<QuerySolution> newIterator = FluentIterable.from(rs);
>>> 
>>> newIterator.skip(startOffset);
>>> 
>>> newIterator.limit(rowsCount);
>>> 
>>> 
>>> Unfortunately the first line doesn't work (the ResultSet type is not type of Iterable as expected by FluentIterable).
>>> 
>>> Let me know the right way of paging the query results.
>>> 
>>> 
>>> 
>>> Thanks,
>>> 
>>> Z
>> 
> 


Re: paging the query results

Posted by Andy Seaborne <an...@apache.org>.
Yes - A ResultSet isn't Iterable because you can only read it once 
unless you do something like ResultSetFactory.makeRewindable,
Hence converting to a stream (.sequential() if ordered!)) is nice.

If you are throwing away the part of the results outside the 
startOffset/rowsCount slice, you can add OFFSET & LIMIT to the query 
then the query engine/server can do it, resulting in less bytes.

If you want the client to control it, the streams way is good.

	Andy

On 16/09/15 16:27, ajs6f@virginia.edu wrote:
> One option: Jena is now using Java 8, so you can use the Streams API to do this:
>
> https://stackoverflow.com/questions/29273705/how-to-paginate-a-list-of-objects-in-java-8
>
> ResultSet is an Iterator, so you can convert it to a Stream.
>
> ---
> A. Soroka
> The University of Virginia Library
>
>> On Sep 16, 2015, at 11:19 AM, Zen 98052 <z9...@outlook.com> wrote:
>>
>> Any idea on how to do the paging on the results set?
>>
>> For example in this code:
>>
>>
>> ResultSet rs = qe.execSelect();
>>
>>
>> I was thinking to use com.google.common.collect.FluentIterable, so let say I have the start offset and rows count values.
>>
>> To do the paging logic in naive way would be something like:
>>
>>
>> FluentIterable<QuerySolution> newIterator = FluentIterable.from(rs);
>>
>> newIterator.skip(startOffset);
>>
>> newIterator.limit(rowsCount);
>>
>>
>> Unfortunately the first line doesn't work (the ResultSet type is not type of Iterable as expected by FluentIterable).
>>
>> Let me know the right way of paging the query results.
>>
>>
>>
>> Thanks,
>>
>> Z
>


Re: paging the query results

Posted by "ajs6f@virginia.edu" <aj...@virginia.edu>.
One option: Jena is now using Java 8, so you can use the Streams API to do this:

https://stackoverflow.com/questions/29273705/how-to-paginate-a-list-of-objects-in-java-8

ResultSet is an Iterator, so you can convert it to a Stream.

---
A. Soroka
The University of Virginia Library

> On Sep 16, 2015, at 11:19 AM, Zen 98052 <z9...@outlook.com> wrote:
> 
> Any idea on how to do the paging on the results set?
> 
> For example in this code:
> 
> 
> ResultSet rs = qe.execSelect();
> 
> 
> I was thinking to use com.google.common.collect.FluentIterable, so let say I have the start offset and rows count values.
> 
> To do the paging logic in naive way would be something like:
> 
> 
> FluentIterable<QuerySolution> newIterator = FluentIterable.from(rs);
> 
> newIterator.skip(startOffset);
> 
> newIterator.limit(rowsCount);
> 
> 
> Unfortunately the first line doesn't work (the ResultSet type is not type of Iterable as expected by FluentIterable).
> 
> Let me know the right way of paging the query results.
> 
> 
> 
> Thanks,
> 
> Z


Re: paging the query results

Posted by Zen 98052 <z9...@outlook.com>.
Now I am thinking instead of using FluentIterable, I should implement my own class (that implements ResultSet) with that skipping and limit logic.
Still, let me know if there is better and more efficient way than this. Thanks!

________________________________________
From: Zen 98052 <z9...@outlook.com>
Sent: Wednesday, September 16, 2015 11:19 AM
To: users@jena.apache.org
Subject: paging the query results

Any idea on how to do the paging on the results set?

For example in this code:


ResultSet rs = qe.execSelect();


I was thinking to use com.google.common.collect.FluentIterable, so let say I have the start offset and rows count values.

To do the paging logic in naive way would be something like:


FluentIterable<QuerySolution> newIterator = FluentIterable.from(rs);

newIterator.skip(startOffset);

newIterator.limit(rowsCount);


Unfortunately the first line doesn't work (the ResultSet type is not type of Iterable as expected by FluentIterable).

Let me know the right way of paging the query results.



Thanks,

Z