RDFLib/rdflibissueplayground — Issue #6: assert in SPARQL query when two OPTIONAL are followed by non-OPTIONAL
Author: gjhiggins
Created: 2012-02-20 06:13:58+00:00
State: open

gjhigg...@gmail.com, 2010-09-14T22:20:34.000Z
Issue 90, migrated from rdflib

from rdflib.Graph import *
# This code generate an assert
Graph().query("""select * {
optional { ?a ?b ?c }
optional { ?d ?e ?f }
?x ?y ?z
}""")

# This is OK
Graph().query("""select * {
?x ?y ?z
optional { ?a ?b ?c }
optional { ?d ?e ?f }
}""")

# This is OK
Graph().query("""select * {
optional { ?a ?b ?c }
?x ?y ?z
optional { ?d ?e ?f }
}""")

All three queries now consistently cause an assert failure:

AssertionError: EmptyGraphPatternExpression(..)
function ReduceToAlgebra in Algebra.py at line 166
assert isinstance(left,(Join,BasicGraphPattern)),repr(left)

## Full SPARQL Algebra expression ##
LeftJoin(LeftJoin(BGP((?x,?y,?z)),BGP((?a,?b,?c))),BGP((?d,?e,?f)))
###################################
## Full SPARQL Algebra expression ##
LeftJoin(LeftJoin(BGP((?x,?y,?z)),BGP((?a,?b,?c))),BGP((?d,?e,?f)))
###################################
eval(
LeftJoin
(LeftJoin(BGP( (?x,?y,?z)),
BGP((?a,?b,?c))),
BGP((?d,?e,?f))),
{},
[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']].)

eval(
LeftJoin(BGP((?x,?y,?z)),
BGP((?a,?b,?c))),
{},
[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']].)
## Full SPARQL Algebra expression ##
LeftJoin(EmptyGraphPatternExpression(..),BGP((?d,?e,?f)))
###################################
## Full SPARQL Algebra expression ##
LeftJoin(EmptyGraphPatternExpression(..),BGP((?d,?e,?f)))
###################################
eval(
LeftJoin(EmptyGraphPatternExpression(..),
BGP((?d,?e,?f))),
{},
[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']].)

eval(
EmptyGraphPatternExpression(..),
{},
[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']].)

Comment 1 by christop...@gmail.com
Attaching patch to fix this issue. Does not work with the * select though.

Comment 2 by christop...@gmail.com
The relevant post can be found under http://groups.google.com/group/rdflib-dev/browse_thread/thread/3948a292c4a98bb8#

Comment 3 by gromgull
This issue was closed by revision 136351810d66.

Comment 4 by gromgull
I applied the patch! Sorry about the delay.

It would be nice to have a unittest for this to avoid regression though! Hint hint :)