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

sparql query with sub-query is not working as expected #628

Closed
wrobell opened this issue May 11, 2016 · 1 comment · Fixed by #694
Closed

sparql query with sub-query is not working as expected #628

wrobell opened this issue May 11, 2016 · 1 comment · Fixed by #694
Labels
bug Something isn't working SPARQL
Milestone

Comments

@wrobell
Copy link

wrobell commented May 11, 2016

Please see the example in https://www.w3.org/TR/sparql11-query/#subqueries.

The result of the script below should resemble

y           minName
:bob     "B. Bar"
:carol   "C. Baz"

But we get null instead of minName values

[
    (rdflib.term.URIRef('http://people.example/bob'), None),
    (rdflib.term.URIRef('http://people.example/carol'), None)
]

The script

import rdflib
import io

data = """
@prefix : <http://people.example/> .

:alice :name "Alice", "Alice Foo", "A. Foo" .
:alice :knows :bob, :carol .
:bob :name "Bob", "Bob Bar", "B. Bar" .
:carol :name "Carol", "Carol Baz", "C. Baz" .
"""

graph = rdflib.Graph()

f = io.StringIO(data)
graph.parse(f, format='n3')

result = graph.query("""
PREFIX : <http://people.example/>
PREFIX : <http://people.example/>

SELECT ?y ?minName
WHERE {
  :alice :knows ?y .
  {
    SELECT ?y (MIN(?name) AS ?minName)
    WHERE {
      ?y :name ?name .
    } GROUP BY ?y
  }
}
""")

print(list(result))
@joernhees joernhees added this to the rdflib 4.2.2 milestone May 12, 2016
@joernhees joernhees added bug Something isn't working SPARQL labels May 12, 2016
@gromgull
Copy link
Member

related #607?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SPARQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants