You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Wang Dongsheng <ds...@gmail.com> on 2013/10/22 09:24:21 UTC

How can I implement pagination for ResultSet

Hi, all
I want to implement pagination for ResultSet of Sparql.
I guess there are generally two ways:

1, Through a specified SPARQL format, but I dont know how to write the query,
2. Get the size of ResultSet. but there are no way to get the total
number that ResultSet contains.

I prefer to implement the second way, But Doc of API seems unavailable.

Any one tried this kind of effort? Or it was not suitable to paginate
the result?

Thank in advance~

Re: How can I implement pagination for ResultSet

Posted by Andy Seaborne <an...@apache.org>.
On 22/10/13 18:21, Wang Dongsheng wrote:
> By the way, I want to ask you two questions accordingly,
>
> For 1), Can I get the total number first? cause it's better to
> calculate how much pages there are in advance.

ResultsSets are an iterator (and streaming whereever possible).  The 
count is not known until the end.

So to get the count, somethgin needs to have seen the whole result set. 
  The ResultSetFactory has functions to create a rewindable result set 
(which is taking a copy) or operations to convert to a list.

> For 2), If the resultSet is very Large, will the transferring to List
> being broken up easily?

How large is "very large"?

You'll have to do that in your code if you want, for example, 
spill-to-disk structures.

Jena has code that that may help you doing that - see DataBag in 
org.apache.jena.atlas.data - or you can simply write the ResultSet to 
disk in one of the SPARQL Results formats, which are themselves 
streaming.  TSV is the fastest.  (CSV is loses information - do not use 
for this situation.)

You then know the size of the results, and have stabilized the results 
against updates or against execution to give a different order (rather 
unlikely in Jena, but you haven't said if your executing against a jena 
endpoint or some remote, other system endpoint).

	Andy


>
> On Tue, Oct 22, 2013 at 6:31 PM, Wang Dongsheng <ds...@gmail.com> wrote:
>> Hi Samuel,
>>   Thanks a lot, It's very cool~ :)
>>
>> Sincere~
>> Wang
>>
>>
>>
>> On Tue, Oct 22, 2013 at 4:22 PM, Samuel Croset <sa...@gmail.com> wrote:
>>> Hi,
>>>
>>> For 1) you can use the OFFSET and LIMIT constructs
>>> For 2) You can use:  ResultSetFormatter.toList()
>>>
>>> See this answer
>>> http://answers.semanticweb.com/questions/9456/jena-pagination-for-sparql for
>>> more details.
>>>
>>> Cheers,
>>>
>>> Samuel
>>>
>>>
>>> On Tue, Oct 22, 2013 at 8:24 AM, Wang Dongsheng <ds...@gmail.com>wrote:
>>>
>>>> Hi, all
>>>> I want to implement pagination for ResultSet of Sparql.
>>>> I guess there are generally two ways:
>>>>
>>>> 1, Through a specified SPARQL format, but I dont know how to write the
>>>> query,
>>>> 2. Get the size of ResultSet. but there are no way to get the total
>>>> number that ResultSet contains.
>>>>
>>>> I prefer to implement the second way, But Doc of API seems unavailable.
>>>>
>>>> Any one tried this kind of effort? Or it was not suitable to paginate
>>>> the result?
>>>>
>>>> Thank in advance~
>>>>


Re: How can I implement pagination for ResultSet

Posted by Claus Stadler <cs...@informatik.uni-leipzig.de>.
Hi,

For the pagination issue combined with client side caching (and adding 
delay for not overloading the endpoint), I have written this utility lib 
some time ago:

https://github.com/AKSW/jena-sparql-api

Its currently for the prior Jena 2.10.0, but will be upgraded soon.

As for

 >> 2) Get the size of ResultSet. but there are no way to get the total 
number that ResultSet contains.

A cheap way of getting the count is doing a query for it with "Select 
(Count(*) As ?c) { { <your original query here>} }". Although I prefer 
modifying the projection in Jena's Query object as I dislike string hacks.


Best,
Claus


On 22.10.2013 19:21, Wang Dongsheng wrote:
> By the way, I want to ask you two questions accordingly,
>
> For 1), Can I get the total number first? cause it's better to
> calculate how much pages there are in advance.
> For 2), If the resultSet is very Large, will the transferring to List
> being broken up easily?
>
> On Tue, Oct 22, 2013 at 6:31 PM, Wang Dongsheng <ds...@gmail.com> wrote:
>> Hi Samuel,
>>   Thanks a lot, It's very cool~ :)
>>
>> Sincere~
>> Wang
>>
>>
>>
>> On Tue, Oct 22, 2013 at 4:22 PM, Samuel Croset <sa...@gmail.com> wrote:
>>> Hi,
>>>
>>> For 1) you can use the OFFSET and LIMIT constructs
>>> For 2) You can use:  ResultSetFormatter.toList()
>>>
>>> See this answer
>>> http://answers.semanticweb.com/questions/9456/jena-pagination-for-sparql for
>>> more details.
>>>
>>> Cheers,
>>>
>>> Samuel
>>>
>>>
>>> On Tue, Oct 22, 2013 at 8:24 AM, Wang Dongsheng <ds...@gmail.com>wrote:
>>>
>>>> Hi, all
>>>> I want to implement pagination for ResultSet of Sparql.
>>>> I guess there are generally two ways:
>>>>
>>>> 1, Through a specified SPARQL format, but I dont know how to write the
>>>> query,
>>>> 2. Get the size of ResultSet. but there are no way to get the total
>>>> number that ResultSet contains.
>>>>
>>>> I prefer to implement the second way, But Doc of API seems unavailable.
>>>>
>>>> Any one tried this kind of effort? Or it was not suitable to paginate
>>>> the result?
>>>>
>>>> Thank in advance~
>>>>


-- 
Dipl. Inf. Claus Stadler
Department of Computer Science, University of Leipzig
Research Group: http://aksw.org/
Workpage & WebID: http://aksw.org/ClausStadler
Phone: +49 341 97-32260


Re: How can I implement pagination for ResultSet

Posted by Wang Dongsheng <ds...@gmail.com>.
By the way, I want to ask you two questions accordingly,

For 1), Can I get the total number first? cause it's better to
calculate how much pages there are in advance.
For 2), If the resultSet is very Large, will the transferring to List
being broken up easily?

On Tue, Oct 22, 2013 at 6:31 PM, Wang Dongsheng <ds...@gmail.com> wrote:
> Hi Samuel,
>  Thanks a lot, It's very cool~ :)
>
> Sincere~
> Wang
>
>
>
> On Tue, Oct 22, 2013 at 4:22 PM, Samuel Croset <sa...@gmail.com> wrote:
>> Hi,
>>
>> For 1) you can use the OFFSET and LIMIT constructs
>> For 2) You can use:  ResultSetFormatter.toList()
>>
>> See this answer
>> http://answers.semanticweb.com/questions/9456/jena-pagination-for-sparql for
>> more details.
>>
>> Cheers,
>>
>> Samuel
>>
>>
>> On Tue, Oct 22, 2013 at 8:24 AM, Wang Dongsheng <ds...@gmail.com>wrote:
>>
>>> Hi, all
>>> I want to implement pagination for ResultSet of Sparql.
>>> I guess there are generally two ways:
>>>
>>> 1, Through a specified SPARQL format, but I dont know how to write the
>>> query,
>>> 2. Get the size of ResultSet. but there are no way to get the total
>>> number that ResultSet contains.
>>>
>>> I prefer to implement the second way, But Doc of API seems unavailable.
>>>
>>> Any one tried this kind of effort? Or it was not suitable to paginate
>>> the result?
>>>
>>> Thank in advance~
>>>

Re: How can I implement pagination for ResultSet

Posted by Wang Dongsheng <ds...@gmail.com>.
Hi Samuel,
 Thanks a lot, It's very cool~ :)

Sincere~
Wang



On Tue, Oct 22, 2013 at 4:22 PM, Samuel Croset <sa...@gmail.com> wrote:
> Hi,
>
> For 1) you can use the OFFSET and LIMIT constructs
> For 2) You can use:  ResultSetFormatter.toList()
>
> See this answer
> http://answers.semanticweb.com/questions/9456/jena-pagination-for-sparql for
> more details.
>
> Cheers,
>
> Samuel
>
>
> On Tue, Oct 22, 2013 at 8:24 AM, Wang Dongsheng <ds...@gmail.com>wrote:
>
>> Hi, all
>> I want to implement pagination for ResultSet of Sparql.
>> I guess there are generally two ways:
>>
>> 1, Through a specified SPARQL format, but I dont know how to write the
>> query,
>> 2. Get the size of ResultSet. but there are no way to get the total
>> number that ResultSet contains.
>>
>> I prefer to implement the second way, But Doc of API seems unavailable.
>>
>> Any one tried this kind of effort? Or it was not suitable to paginate
>> the result?
>>
>> Thank in advance~
>>

Re: How can I implement pagination for ResultSet

Posted by Samuel Croset <sa...@gmail.com>.
Hi,

For 1) you can use the OFFSET and LIMIT constructs
For 2) You can use:  ResultSetFormatter.toList()

See this answer
http://answers.semanticweb.com/questions/9456/jena-pagination-for-sparql for
more details.

Cheers,

Samuel


On Tue, Oct 22, 2013 at 8:24 AM, Wang Dongsheng <ds...@gmail.com>wrote:

> Hi, all
> I want to implement pagination for ResultSet of Sparql.
> I guess there are generally two ways:
>
> 1, Through a specified SPARQL format, but I dont know how to write the
> query,
> 2. Get the size of ResultSet. but there are no way to get the total
> number that ResultSet contains.
>
> I prefer to implement the second way, But Doc of API seems unavailable.
>
> Any one tried this kind of effort? Or it was not suitable to paginate
> the result?
>
> Thank in advance~
>