Fix bug preventing nested FILTER statements from working (#709) by mgberg · Pull Request #2822 · RDFLib/rdflib (original) (raw)

Summary of changes

Disclaimer: I am not super familiar with the SPARQL algebra/translation code in RDFLib, so I'm not confident this is the best solution. Also I'm not 100% confident this will solve all nested filter issues.

This fixes an issue which allows nested filters to work as discussed in #709. Previously, a graph pattern could be passed to rdflib.plugins.sparql.algebra::translateGroupGraphPattern multiple times. If this occurs, the graph pattern would get overwritten with an empty pattern, causing the nested filters to appear to be dropped in the query plan. This modifies translateGroupGraphPattern to:

  1. Mark translated graph patterns as translated, and
  2. Simply return the provided graph pattern if it already has been translated.

Additionally, this includes two new test cases compiled by @ajnelson-nist that verifies that known nested filter issues work (at least those discussed in #709).

Checklist