Skip to content

fix(sparql): return no solutions for a GROUP BY with no matches - #3498

Open
Sanjays2402 wants to merge 1 commit into
RDFLib:mainfrom
Sanjays2402:fix/group-by-empty-result
Open

fix(sparql): return no solutions for a GROUP BY with no matches#3498
Sanjays2402 wants to merge 1 commit into
RDFLib:mainfrom
Sanjays2402:fix/group-by-empty-result

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #3382

Summary of changes

evalAggregateJoin yielded a single empty solution whenever the aggregation
produced zero groups, regardless of whether the query used GROUP BY. An
explicit GROUP BY that matches nothing has zero groups, so the result must be
empty, but rdflib reported a malformed row with no variable bindings:

>>> Dataset().query("SELECT ?s (count(?o) as ?n) { ?s <some:predicate> ?o } GROUP BY ?s").bindings
[{}]      # expected: []

The fallback row is now only yielded for an implicit (ungrouped) aggregate,
where SPARQL does require exactly one solution. Backwards compatible for every
other case.

Checklist

  • Checked that there aren't other open pull requests for
    the same change.
  • Checked that all tests and type checking passes.
  • If the change has a potential impact on users of this project:
    • Added or updated tests that fail without the change.
    • Updated relevant documentation to avoid inaccuracies.
    • Considered adding additional documentation.
  • Considered granting push permissions to the PR branch,
    so maintainers can fix minor issues and keep your PR up to date.

test/test_sparql/ is green (431 passed), and the two new tests in
test/test_sparql/test_agg_undef.py cover both the grouped and ungrouped empty
cases. This change was prepared with AI assistance; the regression test was run
locally and fails without the fix.

evalAggregateJoin yielded a single empty solution whenever the
aggregation produced zero groups, regardless of whether the query used
GROUP BY. For an explicit GROUP BY that matches nothing there are zero
groups, so the result must be empty, but rdflib reported a malformed row
with no variable bindings (Result.bindings == [{}]).

Only yield that fallback row for an implicit (ungrouped) aggregate,
where SPARQL does require exactly one solution.

Adds regression tests for both the grouped and ungrouped empty cases.

Closes RDFLib#3382
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

Successfully merging this pull request may close these issues.

Malformed empty result for GROUP BY query on Dataset

1 participant