Skip to content

Commit

Permalink
apacheGH-1615: Evaluation for lateral
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Nov 19, 2022
1 parent cb91f72 commit 5902da7
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,14 @@ private static Op apply(ExprList exprs, Op subOp) {
// ---- Check if the subOp is the right shape to transform.
Op op = subOp;

// Special case : deduce that the filter will always "eval unbound"
// hence eliminate all rows. Return the empty table.
// LATERAL : This is not longer true.
// // Special case : deduce that the filter will always "eval unbound"
// // hence eliminate all rows. Return the empty table.
// if (testSpecialCaseUnused(subOp, joins, remaining))
// return OpTable.empty();
// But simply skipping this causes (filter) to become (assign) which fails as (assign) does not handle errors.
if (testSpecialCaseUnused(subOp, joins, remaining))
return OpTable.empty();
return null;

// Special case: the deep left op of a OpConditional/OpLeftJoin is unit
// table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,49 @@
* This class supports a QueryIter that takes one QueryIterator as input. */
public abstract class QueryIter1 extends QueryIter
{
private QueryIterator input ;

public QueryIter1(QueryIterator input, ExecutionContext execCxt)
{
super(execCxt) ;
this.input = input ;
private QueryIterator input;

public QueryIter1(QueryIterator input, ExecutionContext execCxt) {
super(execCxt);
this.input = input;
}

protected QueryIterator getInput() { return input ; }

@Override
protected final
void closeIterator()
{
closeSubIterator() ;
performClose(input) ;
input = null ;
protected final void closeIterator() {
closeSubIterator();
performClose(input);
input = null;
}

@Override
protected final
void requestCancel()
{
requestSubCancel() ;
performRequestCancel(input) ;
protected final void requestCancel() {
requestSubCancel();
performRequestCancel(input);
}

/** Cancellation of the query execution is happening */
protected abstract void requestSubCancel() ;

/** Pass on the close method - no need to close the QueryIterator passed to the QueryIter1 constructor */
protected abstract void closeSubIterator() ;

protected abstract void requestSubCancel();

/**
* Pass on the close method - no need to close the QueryIterator passed to the
* QueryIter1 constructor
*/
protected abstract void closeSubIterator();

// Do better
@Override
public void output(IndentedWriter out, SerializationContext sCxt)
{
public void output(IndentedWriter out, SerializationContext sCxt) {
// Linear form.
if ( getInput() != null )
// Closed
getInput().output(out, sCxt) ;
getInput().output(out, sCxt);
else
out.println("Closed");
out.ensureStartOfLine() ;
details(out, sCxt) ;
out.ensureStartOfLine() ;
out.ensureStartOfLine();
details(out, sCxt);
out.ensureStartOfLine();

// details(out, sCxt) ;
// out.ensureStartOfLine() ;
Expand All @@ -83,9 +80,7 @@ public void output(IndentedWriter out, SerializationContext sCxt)
// out.ensureStartOfLine() ;
}

protected void details(IndentedWriter out, SerializationContext sCxt)
{
out.println(Lib.className(this)) ;
protected void details(IndentedWriter out, SerializationContext sCxt) {
out.println(Lib.className(this));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jena.sparql.engine.iterator;

import org.apache.jena.sparql.algebra.Op;
import org.apache.jena.sparql.algebra.op.OpTable;
import org.apache.jena.sparql.core.Substitute;
import org.apache.jena.sparql.engine.ExecutionContext;
import org.apache.jena.sparql.engine.QueryIterator;
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.sparql.engine.main.QC;

public class QueryIterLateral extends QueryIterRepeatApply {

private final Op lateralOp;
private final boolean isUnit;

public QueryIterLateral(QueryIterator input, Op lateralOp, ExecutionContext execCxt) {
super(input, execCxt);
this.lateralOp = lateralOp;
this.isUnit = isJoinIdentity(lateralOp);
}

private boolean isJoinIdentity(Op op) {
if( ! ( op instanceof OpTable ) )
return false;
OpTable table = (OpTable)lateralOp;
return table.isJoinIdentity();
}

@Override
protected QueryIterator nextStage(Binding binding) {
if ( isUnit )
return QueryIterSingleton.create(binding, super.getExecContext());
Op op = Substitute.substitute(lateralOp, binding);
return QC.execute(op, binding, super.getExecContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.ArrayDeque;
import java.util.Deque;

import org.apache.jena.atlas.lib.NotImplemented;
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.sparql.algebra.Op;
import org.apache.jena.sparql.algebra.OpVisitor;
Expand Down Expand Up @@ -156,8 +155,6 @@ public void visit(OpUnion opUnion) {

@Override
public void visit(OpLateral opLateral) {
if ( true )
throw new NotImplemented("EvaluatorDispatch.visit(OpLateral)");
QueryIterator input = pop();
QueryIterator qIter = opExecutor.execute(opLateral, input);
push(qIter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Set;

import org.apache.jena.atlas.iterator.Iter;
import org.apache.jena.atlas.lib.NotImplemented;
import org.apache.jena.graph.Node;
import org.apache.jena.query.ARQ;
import org.apache.jena.query.QueryExecException;
Expand All @@ -41,7 +40,9 @@
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.sparql.engine.iterator.*;
import org.apache.jena.sparql.engine.join.Join;
import org.apache.jena.sparql.engine.main.iterator.*;
import org.apache.jena.sparql.engine.main.iterator.QueryIterGraph;
import org.apache.jena.sparql.engine.main.iterator.QueryIterOptionalIndex;
import org.apache.jena.sparql.engine.main.iterator.QueryIterUnion;
import org.apache.jena.sparql.expr.Expr;
import org.apache.jena.sparql.expr.ExprList;
import org.apache.jena.sparql.procedure.ProcEval;
Expand Down Expand Up @@ -235,11 +236,8 @@ protected QueryIterator execute(OpLeftJoin opLeftJoin, QueryIterator input) {

protected QueryIterator execute(OpLateral opLateral, QueryIterator input) {
QueryIterator left = exec(opLateral.getLeft(), input);
if ( true )
throw new NotImplemented();
// QueryIterator qIter = new QueryIterOptionalIndex(left,
// opCondition.getRight(), execCxt) ;
QueryIterator qIter = null;
// For each row, substitute and execute.
QueryIterator qIter = new QueryIterLateral(left, opLateral.getRight(), execCxt);
return qIter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ private static void combinefilterMentions(VarUsageVisitor usage, Set<Var> mentio

@Override
public void visit(OpLateral opLateral) {
// [LATERAL] ???
mergeVars(opLateral.getLeft());
mergeVars(opLateral.getRight());
}
Expand Down

0 comments on commit 5902da7

Please sign in to comment.