Skip to content

Commit

Permalink
apacheGH-1615: Ref evaluation for lateral
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Nov 13, 2022
1 parent f0139f4 commit 7ca9224
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.jena.graph.Node;
import org.apache.jena.query.SortCondition;
import org.apache.jena.sparql.algebra.Op;
import org.apache.jena.sparql.algebra.Table;
import org.apache.jena.sparql.core.BasicPattern;
import org.apache.jena.sparql.core.TriplePath;
Expand Down Expand Up @@ -51,7 +52,7 @@ public interface Evaluator
public Table diff(Table tableLeft, Table tableRight);
public Table minus(Table left, Table right);
public Table union(Table tableLeft, Table tableRight);
//public Table lateral(Table left, Op right, List<Var> vars);
public Table lateral(Table left, Op right);
public Table condition(Table left, Table right);

public Table filter(ExprList expressions, Table tableLeft);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Deque;
import java.util.Iterator;

import org.apache.jena.atlas.lib.NotImplemented;
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.query.ARQ;
import org.apache.jena.query.QueryExecException;
Expand Down Expand Up @@ -203,12 +202,8 @@ public void visit(OpConditional opCond)
@Override
public void visit(OpLateral opLateral)
{
if ( true )
throw new NotImplemented();
Table left = eval(opLateral.getLeft());
// But right is substitute and eval.
//Table table = evaluator.lateral(left, opLateral.getRight(), opLateral.vars());
Table table = null;
Table table = evaluator.lateral(left, opLateral.getRight());
push(table);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@
import org.apache.jena.query.ResultSet;
import org.apache.jena.query.ResultSetFormatter;
import org.apache.jena.query.SortCondition;
import org.apache.jena.sparql.algebra.Algebra;
import org.apache.jena.sparql.algebra.JoinType;
import org.apache.jena.sparql.algebra.Table;
import org.apache.jena.sparql.algebra.TableFactory;
import org.apache.jena.sparql.algebra.*;
import org.apache.jena.sparql.algebra.table.TableN;
import org.apache.jena.sparql.core.BasicPattern;
import org.apache.jena.sparql.core.TriplePath;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.core.VarExprList;
import org.apache.jena.sparql.core.*;
import org.apache.jena.sparql.engine.ExecutionContext;
import org.apache.jena.sparql.engine.QueryIterator;
import org.apache.jena.sparql.engine.ResultSetStream;
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.sparql.engine.binding.BindingBuilder;
import org.apache.jena.sparql.engine.iterator.*;
import org.apache.jena.sparql.engine.main.QC;
import org.apache.jena.sparql.expr.ExprAggregator;
Expand Down Expand Up @@ -174,6 +169,25 @@ public Table condition(Table left, Table right) {
return left;
}

@Override
public Table lateral(Table left, Op right) {
if ( left.isEmpty() ) {
left.close();
return TableFactory.createEmpty();
}
TableN result = new TableN();
left.iterator(getExecContext()).forEachRemaining(binding->{
Op op = Substitute.substitute(right, binding);
Table t = RefEval.eval(this, op);
t.iterator(getExecContext()).forEachRemaining(b->{
Binding b2 = BindingBuilder.create(binding).addAll(b).build();
result.addBinding(b2);
});
});
left.close();
return result;
}

@Override
public Table list(Table table) {
return table;
Expand Down

0 comments on commit 7ca9224

Please sign in to comment.