Skip to content
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

Clarify that it's forbidden to "reassign" from BIND to SELECT #192

Open
VladimirAlexiev opened this issue Sep 15, 2023 · 10 comments
Open

Clarify that it's forbidden to "reassign" from BIND to SELECT #192

VladimirAlexiev opened this issue Sep 15, 2023 · 10 comments

Comments

@VladimirAlexiev
Copy link
Contributor

This query causes stack overflow on Blazegraph (see https://phabricator.wikimedia.org/T346420)

select (sum(?foo) as ?foo) {
  bind(1 as ?foo)
}

A similar query (see above link) returns useful results on GraphDB.

This query returns "No matching records found"

select (?foo+1 as ?foo) {
  bind(1 as ?foo)
}

This query returns foo=1, no problem:

select (?foo as ?foo) {
  bind(1 as ?foo)
}

So my question is: is it forbidden to "reassign" the same var from BIND to SELECT?

Reading through the spec:

  • https://www.w3.org/TR/sparql11-query/#bind: "The variable introduced by the BIND clause must not have been used in the group graph pattern up to the point of use in BIND."
  • https://www.w3.org/TR/sparql11-query/#selectExpressions: "The rules of assignment in SELECT expression are the same as for assignment in BIND. The expression combines variable bindings already in the query solution, or defined earlier in the SELECT clause. The variable may be used in an expression later in the same SELECT clause and may not be be assigned again in the same SELECT clause."
    • This says you can't "assign" the same var twice in SELECT and that vars are brought forward from BIND, but not explicitly that you can't "reassign" from BIND to SELECT

So I'd say the spec is 99% clear that is forbidden, but not 100%.

@VladimirAlexiev
Copy link
Contributor Author

Update from https://phabricator.wikimedia.org/T235540, which shows that the form above is 100% forbidden.

Extra info:

  • rdf4j/GraphDB allows rebinding
  • Virtuoso (dbpedia) allows rebinding (see phabricator bug)
  • Blazegraph allows it for certain situations:
    • COUNT (see phabricator bug)
    • SAMPLE (see phabricator bug)
    • identity rebinding (see above)
    • expression rebinding (not aggregate): but returns no rows
  • Jena (http://sparql.org/sparql.html) returns proper "parse errors"

I think the SPARQL conformance tests should include a check that SPARQL processors return 400 Bad Request for such requests.

@jpmccu
Copy link

jpmccu commented Sep 15, 2023 via email

@namedgraph
Copy link

@jpmccu please create a bug report with your example(s) then. https://github.com/apache/jena/issues

@afs
Copy link
Collaborator

afs commented Sep 16, 2023

The SPARQL 1.1 test suite is maintained by volunteers at https://github.com/w3c/rdf-tests/
Contributions are welcome and important.

I [@VladimirAlexiev] think the SPARQL conformance tests should include a check that SPARQL processors return 400 Bad Request for such requests.

Please check the test suite.

Negative syntax tests syntax-BINDscope6.rq, syntax-BINDscope7.rq and syntax-BINDscope8.rq cover the required scoping rules for BIND in https://www.w3.org/TR/sparql-query/#variableScope. Then there are test such as syntax-SELECTscope2.rq for other forms.

The SPARQL grammar section notes 12 and 13 apply at parse time.
It's a parse time error.

@VladimirAlexiev
Copy link
Contributor Author

@namedgraph re @jpmccu : it's a lacking feature in Blazegraph (and GraphDB), not a bug in Jena.

@VladimirAlexiev
Copy link
Contributor Author

@afs thanks for your clarifications!

@jpmccu
Copy link

jpmccu commented Sep 27, 2023 via email

@afs
Copy link
Collaborator

afs commented Sep 27, 2023

if conformance tests for things like this and other issues

@jpmccu - They are available! See https://github.com/w3c/rdf-tests/

@afs
Copy link
Collaborator

afs commented Sep 27, 2023

@jpmccu - Jena does reorder VALUES if semantically allowed. Please provide a test case or detailed example of what you expect and what actually happens.

@jpmccu
Copy link

jpmccu commented Sep 27, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants