-
Notifications
You must be signed in to change notification settings - Fork 571
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
Fix issue #936 HAVING clause with variable comparison not correctly evaluated #1093
Conversation
Modified the algebra.py file under sparql folder
@devrb can you please provide positive and negative tests to show how this PR solves the issue and doesn't introduce error? Thanks. |
So do you recommend merging this or not? If your tests pass without the change, we shouldn't merge it, unless someone can show that it accomplishes something desirable |
I rewrote the test as pytest-compatible: import pytest
from rdflib import Graph
g = Graph()
data = """
<urn:a> <urn:p> 1 .
<urn:b> <urn:p> 3 .
<urn:c> <urn:q> 1 .
"""
g.parse(data=data, format="turtle")
def test_group_by():
query = "SELECT ?p" "WHERE { ?s ?p ?o } " "GROUP BY ?p"
qres = g.query(query)
assert len(qres) == 2
def test_having_aggregate_eq_literal():
query = (
"SELECT ?p (avg(?o) as ?a) "
"WHERE { ?s ?p ?o } "
"GROUP BY ?p HAVING (avg(?o) = 2 )"
)
qres = g.query(query)
assert len(qres) == 1
def test_having_primary_expression_var_neq_iri():
query = "SELECT ?p " "WHERE { ?s ?p ?o } " "GROUP BY ?p HAVING (?p != <urn:foo> )"
qres = g.query(query)
assert len(qres) == 2 I was able to confirm that
However, the W3C SPARQL1.1 suite doesn't actually test HAVING clauses to any great degree of complexity: $ grep -rni HAVING test/data/suites/w3c/sparql11/
test/data/suites/w3c/sparql11/aggregates/agg-avg-02.rq:7:HAVING (AVG(?o) <= 2.0)
test/data/suites/w3c/sparql11/aggregates/agg07.rq:6:HAVING ( COUNT(*) > 2 )
test/data/suites/w3c/sparql11/aggregates/agg03.rq:6:HAVING (COUNT(?O) > 2 )
test/data/suites/w3c/sparql11/aggregates/agg06.rq:5:HAVING (COUNT(*) > 0 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks okay to me, I think though that rdflib.plugins.sparql.algebra.traverse
is a bit iffy, I think other places where it is used also has problems, but this change seems okay.
Modified the algebra.py file under sparql folder
Fixes #935, #936.