Skip to content

GH-4315 support sparql lateral#5853

Open
m-alreeni wants to merge 4 commits into
eclipse-rdf4j:developfrom
m-alreeni:GH-4315-support-sparql-lateral
Open

GH-4315 support sparql lateral#5853
m-alreeni wants to merge 4 commits into
eclipse-rdf4j:developfrom
m-alreeni:GH-4315-support-sparql-lateral

Conversation

@m-alreeni

Copy link
Copy Markdown

GitHub issue resolved: #4315

Briefly describe the changes proposed in this PR:

Core implementation of SPARQL lateral join functionality

  • Query Evaluation: handle lateral joins and iterating over lateral join results
  • Parser Updates: to recognize lateral join syntax and build lateral join expressions
  • Extended query model visitors to support lateral join traversal

PR Author Checklist (see the contributor guidelines for more details):

  • my pull request is self-contained
  • I've added tests for the changes I made
  • I've applied code formatting (you can use mvn process-resources to format from the command line)
  • I've squashed my commits where necessary
  • every commit message starts with the issue number (GH-xxxx) followed by a meaningful description of the change

@kenwenzel

Copy link
Copy Markdown
Member

Why is this commit rebase to rdf 1.2 in the middle?

@m-alreeni

Copy link
Copy Markdown
Author

Why is this commit rebase to rdf 1.2 in the middle?

The message is wrong and confusing. I'll correct it

@m-alreeni m-alreeni force-pushed the GH-4315-support-sparql-lateral branch from 7310d71 to f049d99 Compare June 3, 2026 13:13
@kenwenzel

Copy link
Copy Markdown
Member

@hmottestad Do you also think that this can be merged?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Lateral as a BinaryTupleOperator, 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.

Comment on lines +3087 to +3105
@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;
}
Comment on lines +45 to +48
@Override
public Set<String> getAssuredBindingNames() {
return getLeftArg().getAssuredBindingNames();
}
Comment on lines +10 to +14
rdfs:label "Lateral" ;
mf:entries
(
:lateral-01
:lateral-02
Comment on lines +149 to +150
// Should have 4 results: subject1 with 2 alternatives, subject2 with 1,
// subject3 with none
@kenwenzel

Copy link
Copy Markdown
Member

@m-alreeni Please take a look at the review above and try to fix the problems (if any).

@hmottestad

Copy link
Copy Markdown
Contributor

I have been reviewing and fixing issues here: #5875

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.

4 participants