GH-4315 support sparql lateral#5853
Conversation
|
Why is this commit rebase to rdf 1.2 in the middle? |
The message is wrong and confusing. I'll correct it |
7310d71 to
f049d99
Compare
|
@hmottestad Do you also think that this can be merged? |
There was a problem hiding this comment.
Pull request overview
Adds core support for SPARQL 1.2-style LATERAL graph patterns to RDF4J, spanning parsing, query model, rendering, and evaluation, with accompanying compliance tests/resources.
Changes:
- Extend the SPARQL parser/AST builder to recognize
LATERAL { ... }and construct a new query algebra node. - Introduce
Lateralas aBinaryTupleOperator, wire it into visitors/rendering, and add evaluation support via a dedicated iterator/evaluation step. - Add new SPARQL 1.2 testsuite resources and a JUnit dynamic test class for LATERAL behavior.
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/manifest-all.ttl | Includes the lateral tests manifest in the SPARQL 1.2 testsuite manifest. |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/manifest.ttl | Declares LATERAL tests (currently only lateral-01/02). |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/data.ttl | Test data used by LATERAL query evaluation tests. |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-01.rq | LATERAL test query (LIMIT). |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-01.srx | Expected results for lateral-01. |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-02.rq | LATERAL test query (OPTIONAL). |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-02.srx | Expected results for lateral-02. |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-03.rq | Additional LATERAL test query (multiple results). |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-03.srx | Expected results for lateral-03. |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-04.rq | Additional LATERAL test query (UNION). |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-04.srx | Expected results for lateral-04. |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-05.rq | Additional LATERAL test query (subselect + filter). |
| testsuites/sparql/src/main/resources/testcases-sparql-1.2/lateral/lateral-05.srx | Expected results for lateral-05. |
| testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/sparql/tests/LateralTest.java | Adds dynamic JUnit tests for basic LATERAL evaluation scenarios. |
| testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/sparql/RepositorySPARQLComplianceTestSuite.java | Registers LATERAL tests into the repository compliance suite. |
| core/queryrender/src/main/java/org/eclipse/rdf4j/queryrender/sparql/SparqlTupleExprRenderer.java | Adds rendering support for the new Lateral algebra node. |
| core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/TupleExprBuilder.java | Builds a Lateral tuple expression from the parsed AST. |
| core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/ast/SyntaxTreeBuilderVisitor.java | Extends AST visitor interface with ASTLateralGraphPattern. |
| core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/ast/SyntaxTreeBuilderTreeConstants.java | Adds AST node id/name for lateral graph pattern. |
| core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/ast/SyntaxTreeBuilderDefaultVisitor.java | Adds default visitation for the new lateral AST node. |
| core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/ast/SyntaxTreeBuilderConstants.java | Adds the LATERAL token and keyword mapping. |
| core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/ast/SyntaxTreeBuilder.java | Generated parser changes to parse LATERAL { ... }. |
| core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/ast/sparql.jjt | Grammar update to introduce LATERAL graph patterns. |
| core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/ast/ASTLateralGraphPattern.java | New generated AST node type for lateral graph patterns. |
| core/queryparser/sparql/src/main/java/org/eclipse/rdf4j/query/parser/sparql/AbstractASTVisitor.java | Ensures AST traversal includes the lateral graph pattern node. |
| core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/QueryModelVisitor.java | Adds meet(Lateral) to the query model visitor API. |
| core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/Lateral.java | Introduces the Lateral query algebra operator. |
| core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/helpers/StatementPatternVisitor.java | Traversal support for the new algebra node. |
| core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/helpers/AbstractSimpleQueryModelVisitor.java | Default visitor support for Lateral. |
| core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/helpers/AbstractQueryModelVisitor.java | Default visitor support for Lateral. |
| core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/iterator/LateralIterator.java | New iterator to evaluate RHS per LHS binding set. |
| core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/impl/evaluationsteps/LateralQueryEvaluationStep.java | New evaluation step to hook Lateral into strategy precompilation. |
| core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/impl/DefaultEvaluationStrategy.java | Wires Lateral into runtime evaluation and precompilation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Override | ||
| public Object visit(ASTLateralGraphPattern node, Object data) throws VisitorException { | ||
| GraphPattern parentGP = graphPattern; | ||
|
|
||
| // The left argument is the current graph pattern so far | ||
| TupleExpr leftArg = graphPattern.buildTupleExpr(); | ||
|
|
||
| // Create a new graph pattern for the lateral block | ||
| graphPattern = new GraphPattern(parentGP); | ||
| node.jjtGetChild(0).jjtAccept(this, null); | ||
| TupleExpr rightArg = graphPattern.buildTupleExpr(); | ||
|
|
||
| // Create the lateral join | ||
| Lateral lateral = new Lateral(leftArg, rightArg); | ||
| parentGP.addRequiredTE(lateral); | ||
| graphPattern = parentGP; | ||
|
|
||
| return null; | ||
| } |
| @Override | ||
| public Set<String> getAssuredBindingNames() { | ||
| return getLeftArg().getAssuredBindingNames(); | ||
| } |
| rdfs:label "Lateral" ; | ||
| mf:entries | ||
| ( | ||
| :lateral-01 | ||
| :lateral-02 |
| // Should have 4 results: subject1 with 2 alternatives, subject2 with 1, | ||
| // subject3 with none |
|
@m-alreeni Please take a look at the review above and try to fix the problems (if any). |
…Pattern, fix assured-binding information, extend tests
|
I have been reviewing and fixing issues here: #5875 |
GitHub issue resolved: #4315
Briefly describe the changes proposed in this PR:
Core implementation of SPARQL lateral join functionality
PR Author Checklist (see the contributor guidelines for more details):
mvn process-resourcesto format from the command line)