Subqueries within SPARQL

44 views
Skip to first unread message

Joe Eberle

unread,
Feb 11, 2008, 11:53:04 AM2/11/08
to TopBraid Composer Users
I recognize this may be better posted to a SPARQL Group but here it is
anyway.

Is there a way to perform a SPARQL subquery. In other words build a
query that uses the results of another subquery.

For example the following works fine:

SELECT ?name ?symbol ?number ?color
WHERE
{
?element :name ?name.
?element :symbol ?symbol.
?element :atomicNumber ?number.
OPTIONAL { ?element :color ?color.}
FILTER (?number > 7)
FILTER (?number < 9)
}
ORDER BY ?number

It finds only oxygen and the order by is unnecessary.

However if I wanted to look for an all elements greater than oxygens
atomic number I would like to try:

SELECT ?name ?symbol ?number ?color
WHERE
{
?element :name ?name.
?element :symbol ?symbol.
?element :atomicNumber ?number.
OPTIONAL { ?element :color ?color.}
FILTER (?number >
(SELECT ?number
WHERE
{?element :atomicNumber ?number.
?element :name ?name.
FILTER (?name = "oxygen")
)
}
ORDER BY ?number

I was just wondering if this was feasible or if I am looking for a
feature covered in the syntax in some other way. If I should post this
question elsewhere just let me know.

Thanks,
Joe


Parsa Mirhaji

unread,
Feb 11, 2008, 12:26:25 PM2/11/08
to topbraid-co...@googlegroups.com
When using TBC to query an Oracle 11g database there is a runtime error
consistency reporting: "Failed to return all query results".
Query is something this simple:

Query:
SELECT ?pat ?s ?d
WHERE {
?pat ?stat ?s.
?s ?d Damage:SevereDamage. }


Error Log:

java.sql.SQLException: ORA-29532: Java call terminated by uncaught Java
exception: oracle.spatial.rdf.server.ParseException: Encountered
"\"1996-04-01\"" at line 1, column 2.
Was expecting one of:
<URI> ...
<QNAME> ...
<VAR> ...

ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 169
ORA-06512: at
"MDSYS.RDF_MATCH_IMPL_T", line 35
ORA-06512: at line 4

at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at
oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at
oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:21
6)
at
oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatem
ent.java:799)
at
oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java
:1037)
at
oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStat
ement.java:839)
at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java
:1132)
at
oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedSta
tement.java:3316)
at
oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatem
ent.java:3361)
at
oracle.spatial.rdf.client.jena.Oracle.executeQuery(Oracle.java:198)
at
oracle.spatial.rdf.client.jena.GraphOracleSem.graphBaseFind(GraphOracleSem.j
ava:1707)
at
com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
at
org.topbraid.core.graph.CachingGraph.find(CachingGraph.java:158)
at
org.topbraid.core.graph.CachingGraph.find(CachingGraph.java:114)
at
org.topbraid.core.graph.DelegatingGraph.find(DelegatingGraph.java:123)

at org.topbraid.core.graph.BufferingGraph.find(BufferingGraph.java:129)

at org.topbraid.core.graph.BufferingGraph.find(BufferingGraph.java:141)

at
com.hp.hpl.jena.graph.compose.MultiUnion.multiGraphFind(MultiUnion.java:187)
at
com.hp.hpl.jena.graph.compose.MultiUnion.graphBaseFind(MultiUnion.java:166)

at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
at
com.hp.hpl.jena.graph.impl.GraphBase.graphBaseFind(GraphBase.java:260)

at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:257)
at
com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.find(QueryTriple.java:
141)
at
com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.applyToTriples(QueryTr
iple.java:145)
at
com.hp.hpl.jena.graph.query.StageElement$FindTriples.run(StageElement.java:5
0)
at
com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.applyToTriples(QueryTr
iple.java:148)
at
com.hp.hpl.jena.graph.query.StageElement$FindTriples.run(StageElement.java:5
0)
at
com.hp.hpl.jena.graph.query.PatternStageBase.run(PatternStageBase.java:53)

at
com.hp.hpl.jena.graph.query.PatternStageBase$Work.run(PatternStageBase.java:
104)
at
com.hp.hpl.jena.graph.query.PatternStageBase$PatternStageThread.run(PatternS
tageBase.java:88)
com.hp.hpl.jena.shared.JenaException: rethrew:
java.sql.SQLException: ORA-29532: Java call terminated by uncaught Java
exception: oracle.spatial.rdf.server.ParseException: Encountered
"\"1996-04-01\"" at line 1, column 2.
Was expecting one of:
<URI> ...
<QNAME> ...
<VAR> ...

ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 169
ORA-06512: at
"MDSYS.RDF_MATCH_IMPL_T", line 35
ORA-06512: at line 4

at
oracle.spatial.rdf.client.jena.GraphOracleSem.graphBaseFind(GraphOracleSem.j
ava:1716)
at
com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
at
org.topbraid.core.graph.CachingGraph.find(CachingGraph.java:158)
at
org.topbraid.core.graph.CachingGraph.find(CachingGraph.java:114)
at
org.topbraid.core.graph.DelegatingGraph.find(DelegatingGraph.java:123)

at org.topbraid.core.graph.BufferingGraph.find(BufferingGraph.java:129)

at org.topbraid.core.graph.BufferingGraph.find(BufferingGraph.java:141)

at
com.hp.hpl.jena.graph.compose.MultiUnion.multiGraphFind(MultiUnion.java:187)
at
com.hp.hpl.jena.graph.compose.MultiUnion.graphBaseFind(MultiUnion.java:166)

at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
at
com.hp.hpl.jena.graph.impl.GraphBase.graphBaseFind(GraphBase.java:260)

at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:257)
at
com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.find(QueryTriple.java:
141)
at
com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.applyToTriples(QueryTr
iple.java:145)
at
com.hp.hpl.jena.graph.query.StageElement$FindTriples.run(StageElement.java:5
0)
at
com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.applyToTriples(QueryTr
iple.java:148)
at
com.hp.hpl.jena.graph.query.StageElement$FindTriples.run(StageElement.java:5
0)
at
com.hp.hpl.jena.graph.query.PatternStageBase.run(PatternStageBase.java:53)

at
com.hp.hpl.jena.graph.query.PatternStageBase$Work.run(PatternStageBase.java:
104)
at
com.hp.hpl.jena.graph.query.PatternStageBase$PatternStageThread.run(PatternS
tageBase.java:88)
Caused by: java.sql.SQLException: ORA-29532: Java call
terminated by uncaught Java exception:
oracle.spatial.rdf.server.ParseException: Encountered "\"1996-04-01\"" at
line 1, column 2.
Was expecting one of:
<URI> ...
<QNAME> ...
<VAR> ...

ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 169
ORA-06512: at
"MDSYS.RDF_MATCH_IMPL_T", line 35
ORA-06512: at line 4

at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at
oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at
oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:21
6)
at
oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatem
ent.java:799)
at
oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java
:1037)
at
oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStat
ement.java:839)
at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java
:1132)
at
oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedSta
tement.java:3316)
at
oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatem
ent.java:3361)
at
oracle.spatial.rdf.client.jena.Oracle.executeQuery(Oracle.java:198)
at
oracle.spatial.rdf.client.jena.GraphOracleSem.graphBaseFind(GraphOracleSem.j
ava:1707)
... 19 more
com.hp.hpl.jena.shared.QueryStageException:
rethrew: com.hp.hpl.jena.shared.JenaException: rethrew:
java.sql.SQLException: ORA-29532: Java call terminated by uncaught Java
exception: oracle.spatial.rdf.server.ParseException: Encountered
"\"1996-04-01\"" at line 1, column 2.
Was expecting one of:
<URI> ...
<QNAME> ...
<VAR> ...

ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 169
ORA-06512: at
"MDSYS.RDF_MATCH_IMPL_T", line 35
ORA-06512: at line 4

at
com.hp.hpl.jena.graph.query.BufferPipe$Finished.<init>(BufferPipe.java:30)

at com.hp.hpl.jena.graph.query.BufferPipe.close(BufferPipe.java:61)
at
com.hp.hpl.jena.graph.query.PatternStageBase.run(PatternStageBase.java:57)

at
com.hp.hpl.jena.graph.query.PatternStageBase$Work.run(PatternStageBase.java:
104)
at
com.hp.hpl.jena.graph.query.PatternStageBase$PatternStageThread.run(PatternS
tageBase.java:88)
Caused by: com.hp.hpl.jena.shared.JenaException: rethrew:
java.sql.SQLException: ORA-29532: Java call terminated by uncaught Java
exception: oracle.spatial.rdf.server.ParseException: Encountered
"\"1996-04-01\"" at line 1, column 2.
Was expecting one of:
<URI> ...
<QNAME> ...
<VAR> ...

ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 169
ORA-06512: at
"MDSYS.RDF_MATCH_IMPL_T", line 35
ORA-06512: at line 4

at
oracle.spatial.rdf.client.jena.GraphOracleSem.graphBaseFind(GraphOracleSem.j
ava:1716)
at
com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
at
org.topbraid.core.graph.CachingGraph.find(CachingGraph.java:158)
at
org.topbraid.core.graph.CachingGraph.find(CachingGraph.java:114)
at
org.topbraid.core.graph.DelegatingGraph.find(DelegatingGraph.java:123)

at org.topbraid.core.graph.BufferingGraph.find(BufferingGraph.java:129)

at org.topbraid.core.graph.BufferingGraph.find(BufferingGraph.java:141)

at
com.hp.hpl.jena.graph.compose.MultiUnion.multiGraphFind(MultiUnion.java:187)
at
com.hp.hpl.jena.graph.compose.MultiUnion.graphBaseFind(MultiUnion.java:166)

at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
at
com.hp.hpl.jena.graph.impl.GraphBase.graphBaseFind(GraphBase.java:260)

at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:257)
at
com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.find(QueryTriple.java:
141)
at
com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.applyToTriples(QueryTr
iple.java:145)
at
com.hp.hpl.jena.graph.query.StageElement$FindTriples.run(StageElement.java:5
0)
at
com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.applyToTriples(QueryTr
iple.java:148)
at
com.hp.hpl.jena.graph.query.StageElement$FindTriples.run(StageElement.java:5
0)
at
com.hp.hpl.jena.graph.query.PatternStageBase.run(PatternStageBase.java:53)

... 2 more
Caused by: java.sql.SQLException: ORA-29532: Java call terminated
by uncaught Java exception: oracle.spatial.rdf.server.ParseException:
Encountered "\"1996-04-01\"" at line 1, column 2.
Was expecting one of:
<URI> ...
<QNAME> ...
<VAR> ...

ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 169
ORA-06512: at
"MDSYS.RDF_MATCH_IMPL_T", line 35
ORA-06512: at line 4

at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at
oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at
oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:21
6)
at
oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatem
ent.java:799)
at
oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java
:1037)
at
oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStat
ement.java:839)
at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java
:1132)
at
oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedSta
tement.java:3316)
at
oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatem
ent.java:3361)
at
oracle.spatial.rdf.client.jena.Oracle.executeQuery(Oracle.java:198)
at
oracle.spatial.rdf.client.jena.GraphOracleSem.graphBaseFind(GraphOracleSem.j
ava:1707)
... 19 more


Holger Knublauch

unread,
Feb 11, 2008, 1:10:05 PM2/11/08
to topbraid-co...@googlegroups.com
Hi Parsa,

this error almost looks like a corrupted triple somewhere, but I need to
ask our Oracle contacts (your patience is appreciated). From the error
message a literal was found where normally only URI nodes or variables
are permitted; as if a literal was used as subject of a triple.

Just to double-check: did you activate server-side inferencing? Which
version of TBC is this?

Thanks,
Holger

Parsa Mirhaji

unread,
Feb 11, 2008, 4:06:18 PM2/11/08
to topbraid-co...@googlegroups.com
The version is 2.4.4. Even when I use the optional{}, which supposedly
should take care of this, it still happens:
Q1:

SELECT ?pat ?s ?d
WHERE { ?pat ?stat ?s.
Optional {?s ?d Damage:SevereDamage. }.}

Q1 breaks with the same error.

Q2:
SELECT ?s ?d
WHERE { ?s ?d Damage:SevereDamage.}

Q2 works and ?s is always a valid URI and not a literal...
\

Holger Knublauch

unread,
Feb 12, 2008, 3:49:06 PM2/12/08
to topbraid-co...@googlegroups.com
Hi Parsa,

the Oracle developers have confirmed that there might be cases in which
SPARQL queries internally operate on literals as predicates or subjects.
Apparently this has been fixed now and I have included the updated
Oracle classes for the next release. I could not test this particular
case because I didn't run into this problem before.

Since we don't have a release date yet, we need to figure out how
critical this issue is for you. If it's a show stopper, we can send you
an intermediate update. Please let me know off-list.

Thanks
Holger

Parsa Mirhaji

unread,
Mar 5, 2008, 2:16:51 PM3/5/08
to topbraid-co...@googlegroups.com, Nevine Eltonsy
Holger
While trying to connect TBC to an Oracle store, it takes extremely long time
and crashes frequently. Probably because it tries to load all resources from
Database? Does the caching and limits in the configuration (for example
loading only 100 instances per class) work or enforced when connecting to a
db?
Probably the best way to deal with these things would be to cache only first
(n) results from both sparql queries or direct calls to the OracleSemModel
(such as OSModel.getResource(URI).listProperties())....

Parsa Mirhaji, MD
Director, The Center for Biosecurity and Public Health Informatics Research
The School of Health Information Sciences
The University of Texas Health Science Center at Houston
Tel: (713) 500-3157
Fax: (713) 500-0370
Assistance (Yukiko Bryson): (713) 500-3901

Holger Knublauch

unread,
Mar 5, 2008, 2:30:20 PM3/5/08
to topbraid-co...@googlegroups.com, Nevine Eltonsy
Parsa,

how big is the database and what is the sequence of events until it
crashes? With crashing, do you mean it just halts in endless loops, or
are there actual error messages somewhere (Error Log)?

Also, I assume you are using TBC 2.5.1 which has significant Oracle
improvements. In particular, before we cache anything, we first ask
Oracle to give us the number of triples that would match. Then, no more
than 100k triples should be pre-loaded of any pattern. In general, our
cache is trying to minimize the communication calls that are needed to
the database.

I am aware however of problems when too many instances are showing up in
lists and SPARQL results: the problem is that the system may take a very
long time to fetch the appropriate queries to select icons and labels
for the result entries. To overcome such scalability problems, please
make sure to set "Max number of instances to display" to a low number in
the TBC preferences.

Your input is appreciated!
Holger

Ann Brooks

unread,
Mar 28, 2008, 6:07:55 AM3/28/08
to TopBraid Composer Users
http://wikipedlla.com/subqueries_within_sparql
> I recognize this may be better posted to a SPARQL Group but here it is
> anyway.
> Is there a way to perform a SPARQL subquery. In other words build a
> query that uses the results of another subquery.
> For example the following works fine:
> SELECT ?name ?symbol ?number ?color
> WHERE
> {
> &nbsp; ?element :name ?name.
> &nbsp; ?element :symbol ?symbol.
> &nbsp; ?element :atomicNumber ?number.
> &nbsp; OPTIONAL { ?element :color ?color.}
> &nbsp; FILTER (?number &gt; 7)
> &nbsp; FILTER (?number &lt; 9)
> }
> >
Reply all
Reply to author
Forward
0 new messages