-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sparql: Variables bound with initBindings not working in some functions #294
Comments
Thanks for the issue report WITH test-case, that's how I like it! Not really the issue here, but I would expect: g.query("SELECT ?target WHERE { }", initBindings={'target': Literal('example')}): print(r) to return no result rows. To me I'll dig in a debug... |
I have no clue what the correct result would be. I found out after bisecting that I mixed up |
hmm... for a values clause after the query the spec [1] says it should be a join between the results and the bindings given, the results in this case being a single empty bgp clause. RDFLib does this and query simplification removes the join all together: python -m rdflib.plugins.sparql.algebra 'select * where {} values ?a { "cake" }'
[[], SelectQuery_{'where': GroupGraphPatternSub_{}, 'valuesClause': ValuesClause_{'var': [?a], 'value': [literal_{'string': rdflib.term.Literal(u'cake')}]}}]
SelectQuery(
p = Project(
p = ToMultiSet(
p = values(
res = [{?a: rdflib.term.Literal(u'cake')}]
_vars = set([])
)
_vars = set([])
)
PV = []
_vars = set([])
)
datasetClause = None
PV = []
_vars = set([])
) This yields a single solution with the binding we wanted Jena (fuseki) does the same. I think we should define initBindings to work exactly like this, as this makes the SPARQLStore implementation correct :) [1] http://www.w3.org/TR/sparql11-query/#sparqlAlgebraFinalValues |
Hmm. Is this equivalent to defining Anyway, your suggestion sounds good to me. (Hrmpf, I should have noted all the |
Hmm - annoying. In optimising the SPARQL engine in the commits around the one you linked, I introduced generators everywhere, and also the ability to pass bindings "up" the query, as this can help you rule-out lots of possible bindings early on in the evaluation, that would in any case be filtered out later on. Consider the contrived example: select * where {
?p a foaf:Person ;
foaf:name "Bob" .
OPTIONAL {
?p foaf:knows ?p2 .
?p2 foaf:mbox <mailto:[email protected]>
}
} According to the algebra the main graph pattern and the optional clause should be executed independently, and then joined, i.e. the optional would bind ALL people who knows bill to For example, in the bind07 example, the This is what the This causes trouble for I guess the simplest fix is to make initBindings actually add another bit to the algebra, as if it had been a VALUES clause. This will take more than a line though, so maybe not today :) |
Thanks, now I understand the problem. You do not need to hurry. Although this broke the build system of my website, it doesn't matter because prepairing the next upload will take several days anyway. |
@gromgull bump? enough cake :p |
Any progress on that matter? I think I tried all possible ways of using initBinding and none of them seem to be working. The URIRefs I am passing never seem to be bound in the SPARQL query |
I think this is the same issue:
|
Same problem here :-(
|
Maybe it makes sense to mention initBindings are broken in the documentation and explain how to work around the issue? For example, to just use formatting operation and .n3() method for literals, like |
@uholzer you said:
So I waited 2.5 years ;) BUT I think I've fixed this now. Now It passes the test-cases mentioned here, but may break something else. It was more complicated than expected - I believe I've covered all of these cases: http://www.w3.org/TR/sparql11-query/#convertSolMod but some weird queries may have algebras where the MultiSet/Join ends up in the wrong place. |
Fix initBindings handling. Fixes #294
Wait, does this mean I didn't update my website for 2.5 years? Oh dear. Thanks for the fix. |
* master: (49 commits) Update reference to "Emulating container types" Avoid class reference to imported function Prevent RDFa parser from failing on time elements with child nodes Second proposed fix for the broken top_level.txt make Prologue and Query new style classes DOC: minor typo in paramater DOC: unamed -> unnamed AuditableStore.commit does not call self.store.commit anymore ignore operations with no effect fixed trivial copy-paste bug added test cases for AuditableStore expanded path comparison ops in order to keep py2.6 support and not use total_ordering let paths be comparable against all nodes. Fixes #545 re-introduces special handling for DCTERMS.title and test for it Fix initBindings handling. Fixes #294 added .n3 methods for path objects Made ClosedNamespace (and _RDFNamespace) inherit from Namespace cleaned up trailing whitespace Small but nice SPARQL Optimisation fix test for #546 from_n3 trailing backslash ...
My fix to this was no good. I made it insert a values clause, which is then joined to the result of the body. The select projection is then done after the join. So all of @uholzer tests works. But ideally we want initBindings to be bound everywhere in the query. Also inside FILTER clauses and elsewhere. This doesn't really map to any existing SPARQL component, BIND, VALUES, etc. all have special cases of sub-queries/groups where their values disappear from scope. This will require implementing something new - probably reverting to the previous solution, and making sure it's not overwritten by |
initBindings are now special fixed bindings, they are always in scope in all parts of the query. Fixes #294 (once and for all)
initBindings are now special fixed bindings, they are always in scope in all parts of the query. Fixes #294 (once and for all)
3.5 years of 🍰, thanks for digging through this ;) |
Hopefully I'm really misunderstanding the examples here... Here is a sample test case:
and the results:
|
Your |
When I bind a varialbe with
initBindings
and apply to it a function likeSTR
,UCASE
orisLiteral
, I get an unexpected result. Using a BIND or VALUES clause instead ofinitBindings
gives the expected result.Example:
output:
In order to bisect I used this testcase:
I had problems to bisect this. It could be that it only fails some of the time (or I am unable to bisect). It fails starting with commit 1456fe7. Take a look at the diff: Changing
e = _eval(extend.expr, c.forget(ctx))
back toe = _eval(extend.expr, c)
solves this problem. Of course it breaks other things, for example the dawg test case bind07 (explanation). That's all I found out.The text was updated successfully, but these errors were encountered: