You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Milorad Tosic <mb...@yahoo.com> on 2014/02/02 19:29:44 UTC

post processing ResultSet

Hi,

I need to post process ResultSet such that few new columns are custom computed by my code and inserted into the ResultSet. For example, let's have the following result set:

| a | b |
| 1 | 2 |

I would like to return the following resultset instead (that would contain sum c = a + b)

| a | b | c |

| 1 | 2 | 3 |

where c is computed by my Java code and appended to the ResultSet originally obtained as a result of the initial query.

Any advice how this could be done in Jena?

NOTE: I am aware of the possibility to change the original query but that is not an option.

Thanks,
Milorad

Re: post processing ResultSet

Posted by Andy Seaborne <an...@apache.org>.
On 02/02/14 18:29, Milorad Tosic wrote:
> Hi,
>
> I need to post process ResultSet such that few new columns are
> custom  computed by my code and inserted into the ResultSet.
 > For example, let's have the following result set:
>
> | a | b |
> | 1 | 2 |
>
> I would like to return the following resultset instead (that would contain sum c = a + b)
>
> | a | b | c |
>
> | 1 | 2 | 3 |
>
> where c is computed by my Java code and appended to the ResultSet originally obtained as a result of the initial query.
>
> Any advice how this could be done in Jena?
>
> NOTE: I am aware of the possibility to change the original query but that is not an option.

You can write your own ResultSet implementation (it's an interface). 
There are implementations in the code base that may help you.

One way is to use a wrapped pattern - have a new ResultSet 
implementation that uses an underlying one passed in the constructor. 
On each .hasNext/.next call, create a new QuerySolution with the 
additional variable/value.  It's need to copy the QuerySolution in the 
general case.

Or turn the ResultSet into a list, and calculate a new list then use 
ResultSetStream.

Yet another way is to work at the Binding level - BindingFactory. 
binding(Binding parent, Var var, Node node) or QueryIterAssign (which is 
what BIND uses)

	Andy