You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Claude Warren <cl...@apache.org> on 2021/07/03 08:35:51 UTC

Re: Adding subquery to construct query with the query builder


On 2021/04/02 11:02:21, Daniel Jeller <da...@icar-us.eu> wrote: 
> Hi,
> 
> I’m trying to create a CONSTRUCT query using the Jena query builder and I couldn’t figure out how to correctly add a subquery. I’ve tried to create code similar to the following but in the end the expected “Select *” clause is missing, only the where parts are present.
> 
> constructBuilder
> .addConstruct(construct-clauses)
> .addWhere(
> whereBuilder
> .addSubquery(
> SelectBuilder
> .addVar(“*”)
> .addWhere(sub-where)
> )
> .addWhere(outer-where)
> )
> 
> What I’m trying to get is
> 
> CONSTRUCT {
>                construct-clauses
> }
> WHERE {
> SELECT * WHERE { sub-where}
> outer-where
> }
> 
> But what I’m really getting is
> 
> CONSTRUCT {
>                construct-clauses
> }
> WHERE {
> WHERE { sub-where}
> outer-where
> }
> 
> The “Select *” is missing. Am I doing something wrong with my query builder usage?
> 
> Any help is appreciated! Thanks in advance.
> 
> Daniel
> --
> Mag. Daniel Jeller
> Monasterium / Digitisation / IT
> 
> ICARUS
> --
> Spaces Central Station
> Gertrude-Fröhlich-Sander Str. 2-4
> Tower C, Floor 7-9
> A-1100 Vienna
> AUSTRIA
> 
> Web: http://icar-us.eu<http://icar-us.eu/>
> Platforms: http://monasterium.net<http://monasterium.net/>, http//matricula.info
> Join the ICARUS friends‘ association: http://4all.icar-us.eu<http://4all.icar-us.eu/>
> 
> 

Daniel,

Sorry it has taken so long to respond.

There is a pull request to fix this: https://github.com/apache/jena/pull/1026

With the fixes your construction should be simplified.

> constructBuilder
> .addConstruct(construct-clauses)
> .addWhere(
> whereBuilder
> .addSubquery(
> SelectBuilder
> .addVar(“*”)
> .addWhere(sub-where)
> )
> .addWhere(outer-where)
> )
> 

could be written as

new ConstructBuilder()
.addConstruct( construct-clauses )
.addSubquery( new SelectBuilder().addVar("*").addWhere( sub-where ) )
.addWhere( outer-where )

or simplified even further

new ConstructBuilder()
.addConstruct( construct-clauses )
.addSubquery( new WhereBuilder().addWhere( sub-where ) )
.addWhere( outer-where )

Claude