/** Guaranteed to return a new left join*/ public static OpLeftJoin createLeftJoin(Op left, Op right, ExprList exprs) { return new OpLeftJoin(left, right, exprs) ; }
/** * Visiting LeftJoin(Optional) in SPARQL algebra. */ @Override public void visit(final OpLeftJoin opLeftJoin) { optionalFlag = true; optionalVisit(opLeftJoin.getRight()); if (opLeftJoin.getExprs() != null) { for (Expr expr : opLeftJoin.getExprs().getList()) { if (expr != null) { if (optionalFlag) optionalTraversals.add(__.where(WhereTraversalBuilder.transform(expr))); } } } }
@Override public Op transform(OpLeftJoin opLeftJoin, Op opLeft, Op opRight) { ExprList exprList = opLeftJoin.getExprs(); if ( exprList == null ) return opLeftJoin; ExprList exprList2 = process(exprList); if ( exprList2 == null ) return opLeftJoin; return OpLeftJoin.create(opLeft, opRight, exprList2); }
@Override public void visit(OpLeftJoin op) { Op left = null ; Op right = null ; // Must do right-left because the pushes onto the stack were left-right. if ( op.getRight() != null ) right = pop(opStack) ; if ( op.getLeft() != null ) left = pop(opStack) ; ExprList exprs = op.getExprs() ; ExprList exprs2 = collect(exprs) ; OpLeftJoin x = op ; if ( exprs != exprs2 ) x = OpLeftJoin.createLeftJoin(left, right, exprs2) ; Op opX = x.apply(opTransform, left, right) ; push(opStack, opX) ; }
public static Op _optimize(OpLeftJoin op, Set<Set<Expr>> cnf) { // Only push those expression on the, that do not contain any // variables of the right side Set<Var> rightVars = GetVarsMentioned.getVarsMentioned(op.getRight()); Set<Set<Expr>> leftClauses = new HashSet<Set<Expr>>(); Set<Set<Expr>> nonPushable = new HashSet<Set<Expr>>(); for(Set<Expr> clause : cnf) { Set<Var> clauseVars = ClauseUtils.getVarsMentioned(clause); if(Sets.intersection(clauseVars, rightVars).isEmpty()) { leftClauses.add(clause); } else { nonPushable.add(clause); } } Op leftJoin = OpLeftJoin.create(optimize(op.getLeft(), leftClauses), optimize(op.getRight()), new ExprList()); return surroundWithFilterIfNeccessary(leftJoin, nonPushable); }
@Override public Op transform(OpExt op) { Op result; if(op instanceof OpExtLeftJoinSet) { OpExtLeftJoinSet e = (OpExtLeftJoinSet)op; List<Op> items = e.getElements(); result = items.get(0); for(int i = 1; i < items.size(); ++i) { Op right = items.get(i); result = OpLeftJoin.create(result, right, (ExprList)null); } } else { result = op; } return result; } }
@Override public void visit(OpLeftJoin x) { x.getLeft().visit(this); }
/** * Parses the joins and recursively calls the left and right parts */ @Override public void visit(final OpLeftJoin opLeftJoin) { if (LOG.isDebugEnabled()) { LOG.debug("Starting visiting OpLeftJoin"); } final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI); addOp(OpLeftJoin.create(rewriteOp2(opLeftJoin, rewriter), rewriter.getResult(), opLeftJoin.getExprs())); }
@Override public void visit(OpLeftJoin opLeftJoin) { visitOp2(opLeftJoin, opLeftJoin.getExprs()) ; }
@Override public Op transform(OpExt op) { Op result; if(op instanceof OpExtLeftJoinSet) { OpExtLeftJoinSet e = (OpExtLeftJoinSet)op; List<Op> items = e.getElements(); result = items.get(0); for(int i = 1; i < items.size(); ++i) { Op right = items.get(i); result = OpLeftJoin.create(result, right, (ExprList)null); } } else { result = op; } return result; } }
public static RestrictionManagerImpl getRestrictions2(Op op) { if(op instanceof OpFilterIndexed) { return ((OpFilterIndexed) op).getRestrictions(); } else if(op instanceof Op1) { return getRestrictions2(((Op1) op).getSubOp()); } else if(op instanceof OpJoin) { throw new RuntimeException("TODO Merge the restrictions of both sides of the join"); } else if(op instanceof OpLeftJoin) { return getRestrictions2(((OpLeftJoin) op).getLeft()); } else if(op instanceof OpDisjunction) { return null; // TODO We could factor out restrictions common to all elements /*} else if(op instanceof OpSparqlViewPattern) { return null; */ } else { throw new RuntimeException("Should not happen"); } }
@Override public Op transform(OpLeftJoin opLeftJoin, Op left, Op right) { ExprList exprs = opLeftJoin.getExprs(); Op result; if(exprs == null) { OpExtLeftJoinSet r = OpExtLeftJoinSet.create(); add(r, left); add(r, right); result = r; } else { result = OpLeftJoin.create(left, right, exprs); } return result; }