Skip to content

Conversation

PritishWadhwa
Copy link

The order of ResultRows for a SELECT * query was randomized and was changing. This is unexpected because other SPARQL engines seem to generally apply the order of variables as they occur in the WHERE block.

Sample code:

query="SELECT * { ?a ?b ?c } LIMIT 10"
qres=g.query(query)
print(qres.vars)

Expected output:
[rdflib.term.Variable('a'), rdflib.term.Variable('b'), rdflib.term.Variable('c')]

Real output:
[rdflib.term.Variable('c'), rdflib.term.Variable('a'), rdflib.term.Variable('b')] (first run)
[rdflib.term.Variable('a'), rdflib.term.Variable('b'), rdflib.term.Variable('c')] (second run)
[rdflib.term.Variable('b'), rdflib.term.Variable('a'), rdflib.term.Variable('c')] (third run)
[rdflib.term.Variable('a'), rdflib.term.Variable('c'), rdflib.term.Variable('b')] (fourth run)
[you get the idea]

(Tested on the HDT edition of DBpedia 2016, created with g = rdflib.Graph(store=rdflib_hdt.HDTStore(rdf_file)), but that shouldn't matter.)

This was corrected without interfering with the time complexity and the output is now as it should be (as shown in the expected output)

@aucampia
Copy link
Member

aucampia commented May 9, 2022

All changes I see is the addition of a commented function, maybe something is missing? If you are still working on a PR best to mark it as draft.

@coveralls
Copy link

coveralls commented May 9, 2022

Coverage Status

Coverage increased (+0.005%) to 88.243% when pulling d2add04 on PritishWadhwa:Issue166 into eba1373 on RDFLib:master.

@PritishWadhwa
Copy link
Author

PritishWadhwa commented May 9, 2022

All changes I see is the addition of a commented function, maybe something is missing? If you are still working on a PR best to mark it as draft.

Yes I was finalizing something, it is done now

@aucampia
Copy link
Member

aucampia commented May 9, 2022

All changes I see is the addition of a commented function, maybe something is missing? If you are still working on a PR best to mark it as draft.

Yes I was finalizing something, it is done now

Many tests fail now:

https://drone.rdflib.ashs.dev/RDFLib/rdflib/1685/1/2

= 56 failed, 5417 passed, 2 skipped, 117 xfailed, 1 xpassed, 50 warnings in 264.39s (0:04:24) =

Also this PR will need a test that reproduces the broken behavior for it to be merged.

@PritishWadhwa
Copy link
Author

I have made the changes, now the tests which were earlier failing should not fail. I have also added the test file for reproducing the broken behavior.

@ghost
Copy link

ghost commented May 10, 2022

Looking good, all that's left to do in order to satisfy the automated contrib tests is to black the test file.

@PritishWadhwa
Copy link
Author

Looking good, all that's left to do in order to satisfy the automated contrib tests is to black the test file.

Hi. Can you please explain what you mean by "blacking the test file" and how to do it? I am fairly new to open source contribution and haven't seen this term before.

@aucampia
Copy link
Member

pre-commit.ci autofix

@aucampia
Copy link
Member

pre-commit.ci autofix

@PritishWadhwa this is what @gjhiggins meant

I will review this when I can, before Sunday if possible.

from rdflib import Graph


def test_issue_166() -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just briefly, I would much rather prefer this goes into

pytest.param(
"""
SELECT * WHERE {
BIND(
NOT EXISTS {
rdfs:Class rdfs:label "Class"
}
AS ?bound
)
}
""",
[{Variable('bound'): Literal(False)}],
id="select-bind-notexists-const-true",
),
],
)
def test_queries(
query_string: str,
expected_bindings: Sequence[Mapping["Variable", "Identifier"]],
rdfs_graph: Graph,
) -> None:
"""
Results of queries against the rdfs.ttl return the expected values.
"""
query_tree = parseQuery(query_string)
logging.debug("query_tree = %s", prettify_parsetree(query_tree))
logging.debug("query_tree = %s", query_tree)
query = translateQuery(query_tree)
logging.debug("query = %s", query)
query._original_args = (query_string, {}, None)
result = rdfs_graph.query(query)
logging.debug("result = %s", result)
assert expected_bindings == result.bindings

@aucampia
Copy link
Member

Appologies but this will only be reviewed in W20 as #1891 is taking most of my time and I have other priorities also.

@PritishWadhwa
Copy link
Author

Appologies but this will only be reviewed in W20 as #1891 is taking most of my time and I have other priorities also.

Sure, No worries!

@aucampia
Copy link
Member

Just a note, to link this PR to an issue please see:

The way you are doing it makes more involved to find the issue you are referring to.

@aucampia
Copy link
Member

I'm going to first merge typing from #1850 before merging these fixes, this will be in smallish PRs like:

Once these are merged you should rebase this.

In general though the tests should still be integrated.

Furthermore, I think it may be better to use dict or OrderedDict instead of list and a set: https://stackoverflow.com/a/53657523/1598080

@PritishWadhwa
Copy link
Author

I'm going to first merge typing from #1850 before merging these fixes, this will be in smallish PRs like:

Once these are merged you should rebase this.

In general though the tests should still be integrated.

Furthermore, I think it may be better to use dict or OrderedDict instead of list and a set: https://stackoverflow.com/a/53657523/1598080

Sure

Copy link
Member

@aucampia aucampia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comments.

@aucampia aucampia added the needs more work The PR needs more work before being merged or further reviewed. label May 14, 2022
@aucampia
Copy link
Member

Please rebase this branch onto master or merge master into this branch.

@aucampia
Copy link
Member

If there is nothing further on this PR I will close it.

@aucampia
Copy link
Member

Closing this PR due to inactivity, feel free to open it again if you continue working on it again.

@aucampia aucampia closed this Jul 29, 2022
@aucampia
Copy link
Member

Closing this PR due to inactivity, feel free to open it again if you continue working on it again.

@aucampia aucampia reopened this Jul 29, 2022
@aucampia aucampia closed this Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more work The PR needs more work before being merged or further reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants