You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Daniel Jeller <da...@icar-us.eu> on 2021/04/02 11:02:21 UTC

Adding subquery to construct query with the query builder

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/>


Re: Adding subquery to construct query with the query builder

Posted by Claude Warren <cl...@apache.org>.

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

RE: Adding subquery to construct query with the query builder

Posted by Daniel Jeller <da...@icar-us.eu>.
Dear Andy,

I'm sorry, I have been delayed by a project and couldn't create a working example / reproduction of the problem. I still plan to do so. Seeing the issue, I will try to give this a higher priority. Thank you!

Best,
Daniel

-----Original Message-----
From: Andy Seaborne <an...@apache.org> 
Sent: Donnerstag, 15. April 2021 11:04
To: users@jena.apache.org
Subject: Re: Adding subquery to construct query with the query builder

Hi Daniel,

Did you find a way to make this work?

(There is now https://issues.apache.org/jira/browse/JENA-2092
<https://issues.apache.org/jira/browse/JENA-2092> top record the root issue)

     Andy

On 05/04/2021 15:07, Andy Seaborne wrote:
>
> Hi Daniel,
>
> Do you have a complete, minimal example? This needs a JIRA ticket 
> because it should work and I think details are going to matter.
>
> "SELECT *" -- if there are no other SELECT level clauses (e.g. LIMIT) 
> is a no-op as a projection.
>
> Maybe try with named variables.
>
>     Andy
>
>
> On 02/04/2021 12:02, Daniel Jeller 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/>
>>

Re: Adding subquery to construct query with the query builder

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

Did you find a way to make this work?

(There is now https://issues.apache.org/jira/browse/JENA-2092 
<https://issues.apache.org/jira/browse/JENA-2092> top record the root issue)

     Andy

On 05/04/2021 15:07, Andy Seaborne wrote:
>
> Hi Daniel,
>
> Do you have a complete, minimal example? This needs a JIRA ticket 
> because it should work and I think details are going to matter.
>
> "SELECT *" -- if there are no other SELECT level clauses (e.g. LIMIT) 
> is a no-op as a projection.
>
> Maybe try with named variables.
>
>     Andy
>
>
> On 02/04/2021 12:02, Daniel Jeller 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/>
>>

Re: Adding subquery to construct query with the query builder

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

Do you have a complete, minimal example? This needs a JIRA ticket 
because it should work and I think details are going to matter.

"SELECT *" -- if there are no other SELECT level clauses (e.g. LIMIT) is 
a no-op as a projection.

Maybe try with named variables.

     Andy


On 02/04/2021 12:02, Daniel Jeller 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/>
>