org.eclipse.rdf4j.query.algebra.BinaryTupleOperator Java Examples
The following examples show how to use
org.eclipse.rdf4j.query.algebra.BinaryTupleOperator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractExternalSetMatcher.java From rya with Apache License 2.0 | 6 votes |
protected void updateTupleAndNodes() { segmentNodeList = segment.getOrderedNodes(); final TupleExprAndNodes tupAndNodes = segment.getQuery(); tuple = tupAndNodes.getTupleExpr(); filters = tupAndNodes.getFilters(); unmatched = new HashSet<>(); final List<QueryModelNode> nodes = tupAndNodes.getNodes(); for (final QueryModelNode q : nodes) { if (q instanceof UnaryTupleOperator || q instanceof BinaryTupleOperator) { unmatched.add((TupleExpr) q); } else if (q instanceof FlattenedOptional) { final FlattenedOptional opt = (FlattenedOptional) q; final TupleExpr rightArg = opt.getRightArg(); if (rightArg instanceof UnaryTupleOperator || rightArg instanceof BinaryTupleOperator) { unmatched.add(rightArg); } } } }
Example #2
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BinaryTupleOperator expr, BindingSet bindings) throws QueryEvaluationException { if (expr instanceof Join) { return evaluate((Join) expr, bindings); } else if (expr instanceof LeftJoin) { return evaluate((LeftJoin) expr, bindings); } else if (expr instanceof Union) { return evaluate((Union) expr, bindings); } else if (expr instanceof Intersection) { return evaluate((Intersection) expr, bindings); } else if (expr instanceof Difference) { return evaluate((Difference) expr, bindings); } else if (expr == null) { throw new IllegalArgumentException("expr must not be null"); } else { throw new QueryEvaluationException("Unsupported binary tuple operator type: " + expr.getClass()); } }
Example #3
Source File: HalyardTupleExprEvaluation.java From Halyard with Apache License 2.0 | 6 votes |
/** * Evaluate {@link BinaryTupleOperator} query model nodes * @param parent * @param expr * @param bindings */ private void evaluateBinaryTupleOperator(BindingSetPipe parent, BinaryTupleOperator expr, BindingSet bindings) { if (expr instanceof Join) { evaluateJoin(parent, (Join) expr, bindings); } else if (expr instanceof LeftJoin) { evaluateLeftJoin(parent, (LeftJoin) expr, bindings); } else if (expr instanceof Union) { evaluateUnion(parent, (Union) expr, bindings); } else if (expr instanceof Intersection) { evaluateIntersection(parent, (Intersection) expr, bindings); } else if (expr instanceof Difference) { evaluateDifference(parent, (Difference) expr, bindings); } else if (expr == null) { parent.handleException(new IllegalArgumentException("expr must not be null")); } else { parent.handleException(new QueryEvaluationException("Unsupported binary tuple operator type: " + expr.getClass())); } }
Example #4
Source File: QueryModelNodeReplacer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void meetBinaryTupleOperator(BinaryTupleOperator node) { if (node.getLeftArg() == former) { if (replacement == null) { replaceNode(node, node.getRightArg()); } else { node.setLeftArg((TupleExpr) replacement); } } else { assert former == node.getRightArg(); if (replacement == null) { replaceNode(node, node.getLeftArg()); } else { node.setRightArg((TupleExpr) replacement); } } }
Example #5
Source File: AbstractQueryModelVisitor.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void meetOther(QueryModelNode node) throws X { if (node instanceof UnaryTupleOperator) { meetUnaryTupleOperator((UnaryTupleOperator) node); } else if (node instanceof BinaryTupleOperator) { meetBinaryTupleOperator((BinaryTupleOperator) node); } else if (node instanceof CompareSubQueryValueOperator) { meetCompareSubQueryValueOperator((CompareSubQueryValueOperator) node); } else if (node instanceof SubQueryValueOperator) { meetSubQueryValueOperator((SubQueryValueOperator) node); } else if (node instanceof UnaryValueOperator) { meetUnaryValueOperator((UnaryValueOperator) node); } else if (node instanceof BinaryValueOperator) { meetBinaryValueOperator((BinaryValueOperator) node); } else if (node instanceof UpdateExpr) { meetUpdateExpr((UpdateExpr) node); } else { meetNode(node); } }
Example #6
Source File: HalyardTupleExprEvaluation.java From Halyard with Apache License 2.0 | 6 votes |
/** * Switch logic appropriate for each type of {@link TupleExpr} query model node, sending each type to it's appropriate evaluation method. For example, * {@code UnaryTupleOperator} is sent to {@link evaluateUnaryTupleOperator()}. * @param parent * @param expr * @param bindings */ private void evaluateTupleExpr(BindingSetPipe parent, TupleExpr expr, BindingSet bindings) { if (expr instanceof StatementPattern) { statementEvaluation.evaluateStatementPattern(parent, (StatementPattern) expr, bindings); } else if (expr instanceof UnaryTupleOperator) { evaluateUnaryTupleOperator(parent, (UnaryTupleOperator) expr, bindings); } else if (expr instanceof BinaryTupleOperator) { evaluateBinaryTupleOperator(parent, (BinaryTupleOperator) expr, bindings); } else if (expr instanceof SingletonSet) { evaluateSingletonSet(parent, (SingletonSet) expr, bindings); } else if (expr instanceof EmptySet) { evaluateEmptySet(parent, (EmptySet) expr, bindings); } else if (expr instanceof ExternalSet) { evaluateExternalSet(parent, (ExternalSet) expr, bindings); } else if (expr instanceof ZeroLengthPath) { evaluateZeroLengthPath(parent, (ZeroLengthPath) expr, bindings); } else if (expr instanceof ArbitraryLengthPath) { evaluateArbitraryLengthPath(parent, (ArbitraryLengthPath) expr, bindings); } else if (expr instanceof BindingSetAssignment) { evaluateBindingSetAssignment(parent, (BindingSetAssignment) expr, bindings); } else if (expr == null) { parent.handleException(new IllegalArgumentException("expr must not be null")); } else { parent.handleException(new QueryEvaluationException("Unsupported tuple expr type: " + expr.getClass())); } }
Example #7
Source File: BasicGraphPatternExtractor.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
/** * Handles binary nodes with potential BGPs as children (e.g. union, left join). */ @Override public void meetBinaryTupleOperator(BinaryTupleOperator node) { for (TupleExpr expr : new TupleExpr[] { node.getLeftArg(), node.getRightArg() }) { expr.visit(this); if (lastBGPNode != null) { // child is a BGP node but this node is not this.bgpList.add(lastBGPNode); lastBGPNode = null; } } }
Example #8
Source File: TopologyFactory.java From rya with Apache License 2.0 | 5 votes |
/** * Creates a join entry based on a provided {@link IterativeJoin} and the Join's * {@link BinaryTupleOperator}. * * @param id - The ID of the join. * @param joinFunction - The {@link IterativeJoin} function to perform during processing. * @param node - The {@link BinaryTupleOperator} used to create the process. */ private void meetJoin(final String id, final IterativeJoin joinFunction, final BinaryTupleOperator node) { final Set<String> leftArgs = node.getLeftArg().getBindingNames(); final Set<String> rightArgs = node.getRightArg().getBindingNames(); final List<String> joinVars = Lists.newArrayList(Sets.intersection(leftArgs, rightArgs)); leftArgs.removeAll(joinVars); rightArgs.removeAll(joinVars); final List<String> otherVars = new ArrayList<>(); otherVars.addAll(leftArgs); otherVars.addAll(rightArgs); // the join variables need to be sorted so that when compared to all // the variables, the start of the all variable list is congruent to // the join var list. joinVars.sort(Comparator.naturalOrder()); otherVars.sort(Comparator.naturalOrder()); final List<String> allVars = new ArrayList<>(); allVars.addAll(joinVars); allVars.addAll(otherVars); final Optional<Side> side = getSide(node); final JoinProcessorSupplier supplier = new JoinProcessorSupplier(id, joinFunction, joinVars, allVars, result -> getResult(side, result)); entries.add(new ProcessorEntry(node, id, side, supplier, Lists.newArrayList(node.getLeftArg(), node.getRightArg()))); idMap.put(node, id); }
Example #9
Source File: TopologyFactory.java From rya with Apache License 2.0 | 5 votes |
/** * Gets the {@link Side} the current node in the visitor is on relative to the provided node. * @param node - The node used to determine the side of the current visitor node. * @return The {@link Side} the current node is on. */ private Optional<Side> getSide(final QueryModelNode node) { // if query parent is a binary operator, need to determine if it's left or right. if (node.getParentNode() instanceof BinaryTupleOperator) { final BinaryTupleOperator binary = (BinaryTupleOperator) node.getParentNode(); if (node.equals(binary.getLeftArg())) { return Optional.of(Side.LEFT); } else { return Optional.of(Side.RIGHT); } } else { return Optional.empty(); } }
Example #10
Source File: AbstractExternalSetOptimizer.java From rya with Apache License 2.0 | 5 votes |
private Set<TupleExpr> getUnMatchedArgNodes(List<QueryModelNode> nodes) { Set<TupleExpr> unmatched = new HashSet<>(); for (final QueryModelNode q : nodes) { if (q instanceof UnaryTupleOperator || q instanceof BinaryTupleOperator) { unmatched.add((TupleExpr) q); } else if (q instanceof FlattenedOptional) { FlattenedOptional opt = (FlattenedOptional) q; TupleExpr rightArg = opt.getRightArg(); if (rightArg instanceof UnaryTupleOperator || rightArg instanceof BinaryTupleOperator) { unmatched.add(rightArg); } } } return unmatched; }
Example #11
Source File: RdfCloudTripleStoreEvaluationStatistics.java From rya with Apache License 2.0 | 5 votes |
@Override protected void meetBinaryTupleOperator(final BinaryTupleOperator node) { node.getLeftArg().visit(this); final double leftArgCost = cardinality; node.getRightArg().visit(this); cardinality += leftArgCost; }
Example #12
Source File: HalyardEvaluationStatistics.java From Halyard with Apache License 2.0 | 5 votes |
@Override protected void meetBinaryTupleOperator(BinaryTupleOperator node) { node.getLeftArg().visit(this); updateMap(node.getLeftArg()); double leftArgCost = this.cardinality; node.getRightArg().visit(this); updateMap(node.getRightArg()); cardinality += leftArgCost; updateMap(node); }
Example #13
Source File: HalyardEvaluationStatistics.java From Halyard with Apache License 2.0 | 5 votes |
private void meetJoin(BinaryTupleOperator node) { node.getLeftArg().visit(this); updateMap(node.getLeftArg()); double leftArgCost = this.cardinality; Set<String> origBoundVars = boundVars; boundVars = new HashSet<>(boundVars); boundVars.addAll(node.getLeftArg().getBindingNames()); node.getRightArg().visit(this); updateMap(node.getRightArg()); cardinality *= leftArgCost * leftArgCost; boundVars = origBoundVars; updateMap(node); }
Example #14
Source File: AbstractQueryBuilder.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private TupleExpr joinOrExpr(BinaryTupleOperator theExpr) { if (theExpr.getLeftArg() != null && theExpr.getRightArg() == null) { return theExpr.getLeftArg(); } else if (theExpr.getLeftArg() == null && theExpr.getRightArg() != null) { return theExpr.getRightArg(); } else if (theExpr.getLeftArg() == null && theExpr.getRightArg() == null) { return null; } else { return theExpr; } }
Example #15
Source File: QueryModelTreePrinter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void meetNode(QueryModelNode node) { for (int i = 0; i < indentLevel; i++) { sb.append(indentString); } sb.append(node.getSignature()); if (node instanceof VariableScopeChange) { if (((VariableScopeChange) node).isVariableScopeChange()) { sb.append(" (new scope)"); } } if (node instanceof BinaryTupleOperator) { String algorithmName = ((BinaryTupleOperator) node).getAlgorithmName(); if (algorithmName != null) { sb.append(" (").append(algorithmName).append(")"); } } appendCostAnnotation(node, sb); sb.append(LINE_SEPARATOR); indentLevel++; super.meetNode(node); indentLevel--; }
Example #16
Source File: QueryJoinOptimizerTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private TupleExpr findLeaf(TupleExpr expr) { if (expr instanceof UnaryTupleOperator) { return findLeaf(((UnaryTupleOperator) expr).getArg()); } else if (expr instanceof BinaryTupleOperator) { return findLeaf(((BinaryTupleOperator) expr).getLeftArg()); } else { return expr; } }
Example #17
Source File: EvaluationStatistics.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void meetBinaryTupleOperator(BinaryTupleOperator node) { node.getLeftArg().visit(this); double leftArgCost = this.cardinality; node.getRightArg().visit(this); cardinality += leftArgCost; }
Example #18
Source File: EvaluationStatistics.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void meetBinaryTupleOperator(BinaryTupleOperator node) { double cost = 0; for (TupleExpr arg : new TupleExpr[] { node.getLeftArg(), // NOPMD node.getRightArg() }) { arg.visit(this); cost += cardinality; } cardinality = cost; }
Example #19
Source File: GenericInfoOptimizer.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
/** * Handles binary nodes with potential BGPs as children (e.g. union, left join). */ @Override public void meetBinaryTupleOperator(BinaryTupleOperator node) { for (TupleExpr expr : new TupleExpr[] { node.getLeftArg(), node.getRightArg() }) { expr.visit(this); beginNewBGPGroup(); } }
Example #20
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(TupleExpr expr, BindingSet bindings) throws QueryEvaluationException { CloseableIteration<BindingSet, QueryEvaluationException> ret; if (expr instanceof StatementPattern) { ret = evaluate((StatementPattern) expr, bindings); } else if (expr instanceof UnaryTupleOperator) { ret = evaluate((UnaryTupleOperator) expr, bindings); } else if (expr instanceof BinaryTupleOperator) { ret = evaluate((BinaryTupleOperator) expr, bindings); } else if (expr instanceof SingletonSet) { ret = evaluate((SingletonSet) expr, bindings); } else if (expr instanceof EmptySet) { ret = evaluate((EmptySet) expr, bindings); } else if (expr instanceof ExternalSet) { ret = evaluate((ExternalSet) expr, bindings); } else if (expr instanceof ZeroLengthPath) { ret = evaluate((ZeroLengthPath) expr, bindings); } else if (expr instanceof ArbitraryLengthPath) { ret = evaluate((ArbitraryLengthPath) expr, bindings); } else if (expr instanceof BindingSetAssignment) { ret = evaluate((BindingSetAssignment) expr, bindings); } else if (expr instanceof TripleRef) { ret = evaluate((TripleRef) expr, bindings); } else if (expr == null) { throw new IllegalArgumentException("expr must not be null"); } else { throw new QueryEvaluationException("Unsupported tuple expr type: " + expr.getClass()); } if (trackTime) { // set resultsSizeActual to at least be 0 so we can track iterations that don't procude anything expr.setTotalTimeNanosActual(Math.max(0, expr.getTotalTimeNanosActual())); ret = new TimedIterator(ret, expr); } if (trackResultSize) { // set resultsSizeActual to at least be 0 so we can track iterations that don't procude anything expr.setResultSizeActual(Math.max(0, expr.getResultSizeActual())); ret = new ResultSizeCountingIterator(ret, expr); } return ret; }
Example #21
Source File: AbstractQueryModelVisitor.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Method called by all <tt>meet</tt> methods with a {@link BinaryTupleOperator} node as argument. Forwards the call * to {@link #meetNode} by default. * * @param node The node that is being visited. */ protected void meetBinaryTupleOperator(BinaryTupleOperator node) throws X { meetNode(node); }