@Override public int hashCode() { int result = super.hashCode() ^ "LeftJoin".hashCode(); if (hasCondition()) { result ^= getCondition().hashCode(); } return result; }
@Override public int hashCode() { int result = super.hashCode() ^ "LeftJoin".hashCode(); if (hasCondition()) { result ^= getCondition().hashCode(); } return result; }
@Override public boolean equals(Object other) { if (other instanceof LeftJoin && super.equals(other)) { ValueExpr oCond = ((LeftJoin)other).getCondition(); return nullEquals(condition, oCond); } return false; }
/** * @inheritDoc */ @Override public void meet(LeftJoin theJoin) throws Exception { theJoin.getLeftArg().visit(this); mJoinBuffer.append(" ["); theJoin.getRightArg().visit(this); if (theJoin.getCondition() != null) { mJoinBuffer.append(renderValueExpr(theJoin.getCondition())); } mJoinBuffer.setCharAt(mJoinBuffer.lastIndexOf(","), ' '); mJoinBuffer.append("], "); }
/** * @inheritDoc */ @Override public void meet(LeftJoin theJoin) throws Exception { theJoin.getLeftArg().visit(this); mJoinBuffer.append(" ["); theJoin.getRightArg().visit(this); if (theJoin.getCondition() != null) { mJoinBuffer.append(renderValueExpr(theJoin.getCondition())); } mJoinBuffer.setCharAt(mJoinBuffer.lastIndexOf(","), ' '); mJoinBuffer.append("], "); }
@Override public boolean equals(Object other) { if (other instanceof LeftJoin && super.equals(other)) { ValueExpr oCond = ((LeftJoin)other).getCondition(); return nullEquals(condition, oCond); } return false; }
/** * @inheritDoc */ @Override public void meet(LeftJoin theJoin) throws Exception { theJoin.getLeftArg().visit(this); mJoinBuffer.append(" ["); theJoin.getRightArg().visit(this); if (theJoin.getCondition() != null) { mJoinBuffer.append(renderValueExpr(theJoin.getCondition())); } mJoinBuffer.setCharAt(mJoinBuffer.lastIndexOf(","), ' '); mJoinBuffer.append("], "); }
@Override public void meet(LeftJoin node) throws RuntimeException { super.meet(node); if (node.hasCondition()) { meetNode(node.getCondition()); } } }.meetOther(root);
public FlattenedOptional(LeftJoin node) { rightArgs = getJoinArgs(node.getRightArg(), new HashSet<TupleExpr>()); boundVars = setWithOutConstants( Sets.intersection(node.getLeftArg().getAssuredBindingNames(), node.getRightArg().getBindingNames())); unboundVars = setWithOutConstants(Sets.difference(node.getRightArg().getBindingNames(), boundVars)); condition = node.getCondition(); rightArg = node.getRightArg(); getVarCounts(node); assuredBindingNames = new HashSet<>(leftArgVarCounts.keySet()); bindingNames = new HashSet<>(Sets.union(assuredBindingNames, unboundVars)); }
@Override public LeftJoin clone() { LeftJoin clone = (LeftJoin)super.clone(); if (hasCondition()) { clone.setCondition(getCondition().clone()); } return clone; } }
/** * @inheritDoc */ @Override public void meet(LeftJoin theJoin) throws Exception { ctxOpen(theJoin); // try and reverse engineer the original scoping intent of the query final boolean aNeedsNewScope = theJoin.getParentNode() != null && (theJoin.getParentNode() instanceof Join || theJoin.getParentNode() instanceof LeftJoin); if (aNeedsNewScope) { mJoinBuffer.append("{\n"); } theJoin.getLeftArg().visit(this); mJoinBuffer.append(indent()).append("OPTIONAL {\n"); mIndent += 2; theJoin.getRightArg().visit(this); if (theJoin.getCondition() != null) { mJoinBuffer.append(indent()).append("filter").append( renderValueExpr(theJoin.getCondition())).append("\n"); } mIndent -= 2; mJoinBuffer.append(indent()).append("}.\n"); if (aNeedsNewScope) { mJoinBuffer.append("}.\n"); } ctxClose(theJoin); }
/** * @inheritDoc */ @Override public void meet(LeftJoin theJoin) throws Exception { ctxOpen(theJoin); // try and reverse engineer the original scoping intent of the query final boolean aNeedsNewScope = theJoin.getParentNode() != null && (theJoin.getParentNode() instanceof Join || theJoin.getParentNode() instanceof LeftJoin); if (aNeedsNewScope) { mJoinBuffer.append("{\n"); } theJoin.getLeftArg().visit(this); mJoinBuffer.append(indent()).append("OPTIONAL {\n"); mIndent += 2; theJoin.getRightArg().visit(this); if (theJoin.getCondition() != null) { mJoinBuffer.append(indent()).append("filter").append( renderValueExpr(theJoin.getCondition())).append("\n"); } mIndent -= 2; mJoinBuffer.append(indent()).append("}.\n"); if (aNeedsNewScope) { mJoinBuffer.append("}.\n"); } ctxClose(theJoin); }
@Override public LeftJoin clone() { LeftJoin clone = (LeftJoin)super.clone(); if (hasCondition()) { clone.setCondition(getCondition().clone()); } return clone; } }
@Override public void meet(LeftJoin node) { super.meet(node); if (node.getCondition() != null) { List<ValueExpr> conjunctiveConstraints = new ArrayList<ValueExpr>(16); getConjunctiveConstraints(node.getCondition(), conjunctiveConstraints); TupleExpr arg = node.getRightArg(); ValueExpr condition = null; for (ValueExpr constraint : conjunctiveConstraints) { if (isWithinBindingScope(constraint, arg)) { arg = new Filter(arg, constraint); } else if (condition == null) { condition = constraint; } else { condition = new And(condition, constraint); } } node.setCondition(condition); node.setRightArg(arg); } }
@Override public void meet(LeftJoin node) { super.meet(node); if (node.getCondition() != null) { List<ValueExpr> conjunctiveConstraints = new ArrayList<ValueExpr>(16); getConjunctiveConstraints(node.getCondition(), conjunctiveConstraints); TupleExpr arg = node.getRightArg(); ValueExpr condition = null; for (ValueExpr constraint : conjunctiveConstraints) { if (isWithinBindingScope(constraint, arg)) { arg = new Filter(arg, constraint); } else if (condition == null) { condition = constraint; } else { condition = new And(condition, constraint); } } node.setCondition(condition); node.setRightArg(arg); } }
private void buildQuery(final TupleExpr tupleExpr, final StatementPattern matchStatement) { //If our IndexerExpr (to be) is the rhs-child of LeftJoin, we can safely make that a Join: // the IndexerExpr will (currently) not return results that can deliver unbound variables. //This optimization should probably be generalized into a LeftJoin -> Join optimizer under certain conditions. Until that // has been done, this code path at least takes care of queries generated by OpenSahara SparqTool that filter on OPTIONAL // projections. E.g. summary~'full text search' (summary is optional). See #379 if (matchStatement.getParentNode() instanceof LeftJoin) { final LeftJoin leftJoin = (LeftJoin)matchStatement.getParentNode(); if (leftJoin.getRightArg() == matchStatement && leftJoin.getCondition() == null) { matchStatement.getParentNode().replaceWith(new Join(leftJoin.getLeftArg(), leftJoin.getRightArg())); } } final FilterFunction fVisitor = new FilterFunction(matchStatement.getObjectVar().getName()); tupleExpr.visit(fVisitor); final List<IndexingExpr> results = Lists.newArrayList(); for(int i = 0; i < fVisitor.func.size(); i++){ results.add(new IndexingExpr(fVisitor.func.get(i), matchStatement, Arrays.stream(fVisitor.args.get(i)).toArray())); } removeMatchedPattern(tupleExpr, matchStatement, new IndexerExprReplacer(results)); }
/** * Checks whether the left join is "well designed" as defined in section 4.2 of * "Semantics and Complexity of SPARQL", 2006, Jorge Pérez et al. */ private boolean isWellDesigned(LeftJoin leftJoin) { VarNameCollector optionalVarCollector = new VarNameCollector(); leftJoin.getRightArg().visit(optionalVarCollector); if (leftJoin.hasCondition()) { leftJoin.getCondition().visit(optionalVarCollector); } Set<String> problemVars = optionalVarCollector.getVarNames(); problemVars.removeAll(leftJoin.getLeftArg().getBindingNames()); if (problemVars.isEmpty()) { return true; } // If any of the problematic variables are bound in the parent // expression then the left join is not well designed BindingCollector bindingCollector = new BindingCollector(); QueryModelNode node = leftJoin; QueryModelNode parent; while ((parent = node.getParentNode()) != null) { bindingCollector.setNodeToIgnore(node); parent.visitChildren(bindingCollector); node = parent; } problemVars.retainAll(bindingCollector.getBindingNames()); return problemVars.isEmpty(); }
/** * Checks whether the left join is "well designed" as defined in section 4.2 of * "Semantics and Complexity of SPARQL", 2006, Jorge Pérez et al. */ private boolean isWellDesigned(LeftJoin leftJoin) { VarNameCollector optionalVarCollector = new VarNameCollector(); leftJoin.getRightArg().visit(optionalVarCollector); if (leftJoin.hasCondition()) { leftJoin.getCondition().visit(optionalVarCollector); } Set<String> problemVars = optionalVarCollector.getVarNames(); problemVars.removeAll(leftJoin.getLeftArg().getBindingNames()); if (problemVars.isEmpty()) { return true; } // If any of the problematic variables are bound in the parent // expression then the left join is not well designed BindingCollector bindingCollector = new BindingCollector(); QueryModelNode node = leftJoin; QueryModelNode parent; while ((parent = node.getParentNode()) != null) { bindingCollector.setNodeToIgnore(node); parent.visitChildren(bindingCollector); node = parent; } problemVars.retainAll(bindingCollector.getBindingNames()); return problemVars.isEmpty(); }
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(LeftJoin leftJoin, final BindingSet bindings) throws QueryEvaluationException { if (TupleExprs.containsSubquery(leftJoin.getRightArg())) { return new HashJoinIteration(this, leftJoin, bindings); } // Check whether optional join is "well designed" as defined in section // 4.2 of "Semantics and Complexity of SPARQL", 2006, Jorge Pérez et al. VarNameCollector optionalVarCollector = new VarNameCollector(); leftJoin.getRightArg().visit(optionalVarCollector); if (leftJoin.hasCondition()) { leftJoin.getCondition().visit(optionalVarCollector); } Set<String> problemVars = optionalVarCollector.getVarNames(); problemVars.removeAll(leftJoin.getLeftArg().getBindingNames()); problemVars.retainAll(bindings.getBindingNames()); if (problemVars.isEmpty()) { // left join is "well designed" return new LeftJoinIterator(this, leftJoin, bindings); } else { return new BadlyDesignedLeftJoinIterator(this, leftJoin, bindings, problemVars); } }
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(LeftJoin leftJoin, final BindingSet bindings) throws QueryEvaluationException { if (TupleExprs.containsSubquery(leftJoin.getRightArg())) { return new HashJoinIteration(this, leftJoin, bindings); } // Check whether optional join is "well designed" as defined in section // 4.2 of "Semantics and Complexity of SPARQL", 2006, Jorge Pérez et al. VarNameCollector optionalVarCollector = new VarNameCollector(); leftJoin.getRightArg().visit(optionalVarCollector); if (leftJoin.hasCondition()) { leftJoin.getCondition().visit(optionalVarCollector); } Set<String> problemVars = optionalVarCollector.getVarNames(); problemVars.removeAll(leftJoin.getLeftArg().getBindingNames()); problemVars.retainAll(bindings.getBindingNames()); if (problemVars.isEmpty()) { // left join is "well designed" return new LeftJoinIterator(this, leftJoin, bindings); } else { return new BadlyDesignedLeftJoinIterator(this, leftJoin, bindings, problemVars); } }