org.eclipse.rdf4j.query.algebra.EmptySet Java Examples
The following examples show how to use
org.eclipse.rdf4j.query.algebra.EmptySet.
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: 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 #2
Source File: QueryModelNormalizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void meet(Filter node) { super.meet(node); TupleExpr arg = node.getArg(); ValueExpr condition = node.getCondition(); if (arg instanceof EmptySet) { // see #meetUnaryTupleOperator } else if (condition instanceof ValueConstant) { boolean conditionValue; try { conditionValue = QueryEvaluationUtil.getEffectiveBooleanValue(((ValueConstant) condition).getValue()); } catch (ValueExprEvaluationException e) { conditionValue = false; } if (conditionValue == false) { // Constraint is always false node.replaceWith(new EmptySet()); } else { node.replaceWith(arg); } } }
Example #3
Source File: FilterCursor.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public FilterCursor(CloseableIteration<BindingSet, QueryEvaluationException> result, ValueExpr condition, final Set<String> scopeBindingNames, EvaluationStrategy strategy) throws QueryEvaluationException { super(new Filter(new EmptySet() { @Override public Set<String> getBindingNames() { return scopeBindingNames; } }, condition), result, strategy); }
Example #4
Source File: PCJOptimizerUtilities.java From rya with Apache License 2.0 | 5 votes |
@Override public void meet(final EmptySet node) { if (filter.getParentNode() != null) { // Remove filter from its original location filter.replaceWith(filter.getArg()); } }
Example #5
Source File: HalyardTupleExprEvaluation.java From Halyard with Apache License 2.0 | 5 votes |
/** * Evaluate {@link EmptySet} query model nodes * @param parent * @param emptySet * @param bindings */ private void evaluateEmptySet(BindingSetPipe parent, EmptySet emptySet, BindingSet bindings) { try { parent.push(null); } catch (InterruptedException e) { parent.handleException(e); } }
Example #6
Source File: QueryModelNormalizerTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testNormalizeUnionWithEmptyRight() { Projection p = new Projection(); Union union = new Union(); SingletonSet s = new SingletonSet(); union.setRightArg(new EmptySet()); union.setLeftArg(s); p.setArg(union); subject.meet(union); assertThat(p.getArg()).isEqualTo(s); }
Example #7
Source File: QueryModelNormalizerTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testNormalizeUnionWithEmptyLeft() { Projection p = new Projection(); Union union = new Union(); SingletonSet s = new SingletonSet(); union.setLeftArg(new EmptySet()); union.setRightArg(s); p.setArg(union); subject.meet(union); assertThat(p.getArg()).isEqualTo(s); }
Example #8
Source File: QueryModelNormalizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void meetUnaryTupleOperator(UnaryTupleOperator node) { super.meetUnaryTupleOperator(node); if (node.getArg() instanceof EmptySet) { node.replaceWith(node.getArg()); } }
Example #9
Source File: QueryModelNormalizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Intersection intersection) { super.meet(intersection); TupleExpr leftArg = intersection.getLeftArg(); TupleExpr rightArg = intersection.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { intersection.replaceWith(new EmptySet()); } }
Example #10
Source File: QueryModelNormalizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Difference difference) { super.meet(difference); TupleExpr leftArg = difference.getLeftArg(); TupleExpr rightArg = difference.getRightArg(); if (leftArg instanceof EmptySet) { difference.replaceWith(leftArg); } else if (rightArg instanceof EmptySet) { difference.replaceWith(leftArg); } else if (leftArg instanceof SingletonSet && rightArg instanceof SingletonSet) { difference.replaceWith(new EmptySet()); } }
Example #11
Source File: QueryModelNormalizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Union union) { super.meet(union); TupleExpr leftArg = union.getLeftArg(); TupleExpr rightArg = union.getRightArg(); if (leftArg instanceof EmptySet) { union.replaceWith(rightArg); } else if (rightArg instanceof EmptySet) { union.replaceWith(leftArg); } }
Example #12
Source File: QueryModelNormalizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(LeftJoin leftJoin) { super.meet(leftJoin); TupleExpr leftArg = leftJoin.getLeftArg(); TupleExpr rightArg = leftJoin.getRightArg(); ValueExpr condition = leftJoin.getCondition(); if (leftArg instanceof EmptySet) { leftJoin.replaceWith(leftArg); } else if (rightArg instanceof EmptySet) { leftJoin.replaceWith(leftArg); } else if (rightArg instanceof SingletonSet) { leftJoin.replaceWith(leftArg); } else if (condition instanceof ValueConstant) { boolean conditionValue; try { conditionValue = QueryEvaluationUtil.getEffectiveBooleanValue(((ValueConstant) condition).getValue()); } catch (ValueExprEvaluationException e) { conditionValue = false; } if (conditionValue == false) { // Constraint is always false leftJoin.replaceWith(leftArg); } else { leftJoin.setCondition(null); } } }
Example #13
Source File: FilterOptimizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(EmptySet node) { if (filter.getParentNode() != null) { // Remove filter from its original location filter.replaceWith(filter.getArg()); } }
Example #14
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Intersection intersection) { super.meet(intersection); TupleExpr leftArg = intersection.getLeftArg(); TupleExpr rightArg = intersection.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { intersection.replaceWith(new EmptySet()); } }
Example #15
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Intersection intersection) { super.meet(intersection); TupleExpr leftArg = intersection.getLeftArg(); TupleExpr rightArg = intersection.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { intersection.replaceWith(leftArg); } }
Example #16
Source File: AbstractSearchQueryEvaluator.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void replaceQueryPatternsWithResults(final BindingSetAssignment bsa) { final QueryModelNode placeholder = removeQueryPatterns(); if (bsa != null && bsa.getBindingSets() != null && bsa.getBindingSets().iterator().hasNext()) { placeholder.replaceWith(bsa); } else { placeholder.replaceWith(new EmptySet()); } }
Example #17
Source File: EmptyPatternOptimizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(StatementPattern node) throws RepositoryException { Resource subj = (Resource) node.getSubjectVar().getValue(); IRI pred = (IRI) node.getPredicateVar().getValue(); Value obj = node.getObjectVar().getValue(); Resource[] ctx = getContexts(node.getContextVar()); for (RepositoryConnection member : members) { RepositoryBloomFilter bloomFilter = MoreObjects.firstNonNull(bloomFilters.apply(member.getRepository()), AccurateRepositoryBloomFilter.INCLUDE_INFERRED_INSTANCE); if (bloomFilter.mayHaveStatement(member, subj, pred, obj, ctx)) { return; } } node.replaceWith(new EmptySet()); }
Example #18
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void meetMultiJoin(NaryJoin join) { super.meetOther(join); for (TupleExpr arg : join.getArgs()) { if (arg instanceof SingletonSet) { join.removeArg(arg); } else if (arg instanceof EmptySet) { join.replaceWith(new EmptySet()); // NOPMD return; } } if (join.getNumberOfArguments() == 1) { join.replaceWith(join.getArg(0)); } }
Example #19
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Join join) { super.meet(join); TupleExpr leftArg = join.getLeftArg(); TupleExpr rightArg = join.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { join.replaceWith(new EmptySet()); } else if (leftArg instanceof SingletonSet) { join.replaceWith(rightArg); } else if (rightArg instanceof SingletonSet) { join.replaceWith(leftArg); } }
Example #20
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(LeftJoin leftJoin) { super.meet(leftJoin); TupleExpr leftArg = leftJoin.getLeftArg(); TupleExpr rightArg = leftJoin.getRightArg(); ValueExpr condition = leftJoin.getCondition(); if (leftArg instanceof EmptySet) { leftJoin.replaceWith(leftArg); } else if (rightArg instanceof EmptySet) { leftJoin.replaceWith(leftArg); } else if (rightArg instanceof SingletonSet) { leftJoin.replaceWith(leftArg); } else if (condition instanceof ValueConstant) { boolean conditionValue; try { conditionValue = QueryEvaluationUtil .getEffectiveBooleanValue(((ValueConstant) condition).getValue()); } catch (ValueExprEvaluationException e) { conditionValue = false; } if (conditionValue) { leftJoin.setCondition(null); } else { // Constraint is always false leftJoin.replaceWith(leftArg); } } }
Example #21
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Union union) { super.meet(union); TupleExpr leftArg = union.getLeftArg(); TupleExpr rightArg = union.getRightArg(); if (leftArg instanceof EmptySet) { union.replaceWith(rightArg); } else if (rightArg instanceof EmptySet) { union.replaceWith(leftArg); } else if (leftArg instanceof SingletonSet && rightArg instanceof SingletonSet) { union.replaceWith(leftArg); } }
Example #22
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Difference difference) { super.meet(difference); TupleExpr leftArg = difference.getLeftArg(); TupleExpr rightArg = difference.getRightArg(); if (leftArg instanceof EmptySet) { difference.replaceWith(leftArg); } else if (rightArg instanceof EmptySet) { difference.replaceWith(leftArg); } else if (leftArg instanceof SingletonSet && rightArg instanceof SingletonSet) { difference.replaceWith(new EmptySet()); } }
Example #23
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Difference difference) { super.meet(difference); TupleExpr leftArg = difference.getLeftArg(); TupleExpr rightArg = difference.getRightArg(); if (leftArg instanceof EmptySet) { difference.replaceWith(leftArg); } else if (rightArg instanceof EmptySet) { difference.replaceWith(leftArg); } else if (leftArg instanceof SingletonSet && rightArg instanceof SingletonSet) { difference.replaceWith(new EmptySet()); } }
Example #24
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Join join) { super.meet(join); TupleExpr leftArg = join.getLeftArg(); TupleExpr rightArg = join.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { join.replaceWith(new EmptySet()); } else if (leftArg instanceof SingletonSet) { join.replaceWith(rightArg); } else if (rightArg instanceof SingletonSet) { join.replaceWith(leftArg); } }
Example #25
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(LeftJoin leftJoin) { super.meet(leftJoin); TupleExpr leftArg = leftJoin.getLeftArg(); TupleExpr rightArg = leftJoin.getRightArg(); ValueExpr condition = leftJoin.getCondition(); if (leftArg instanceof EmptySet) { leftJoin.replaceWith(leftArg); } else if (rightArg instanceof EmptySet) { leftJoin.replaceWith(leftArg); } else if (rightArg instanceof SingletonSet) { leftJoin.replaceWith(leftArg); } else if (condition instanceof ValueConstant) { boolean conditionValue; try { conditionValue = QueryEvaluationUtil .getEffectiveBooleanValue(((ValueConstant) condition).getValue()); } catch (ValueExprEvaluationException e) { conditionValue = false; } if (conditionValue == false) { // Constraint is always false leftJoin.replaceWith(leftArg); } else { leftJoin.setCondition(null); } } }
Example #26
Source File: QueryModelPruner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(Union union) { super.meet(union); TupleExpr leftArg = union.getLeftArg(); TupleExpr rightArg = union.getRightArg(); if (leftArg instanceof EmptySet) { union.replaceWith(rightArg); } else if (rightArg instanceof EmptySet) { union.replaceWith(leftArg); } else if (leftArg instanceof SingletonSet && rightArg instanceof SingletonSet) { union.replaceWith(leftArg); } }
Example #27
Source File: EvaluationStatistics.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void meet(EmptySet node) { cardinality = 0; }
Example #28
Source File: SameTermFilterOptimizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void meet(Filter filter) { super.meet(filter); if (filter.getCondition() instanceof SameTerm) { // SameTerm applies to the filter's argument SameTerm sameTerm = (SameTerm) filter.getCondition(); TupleExpr filterArg = filter.getArg(); ValueExpr leftArg = sameTerm.getLeftArg(); ValueExpr rightArg = sameTerm.getRightArg(); // Verify that vars are (potentially) bound by filterArg Set<String> bindingNames = filterArg.getBindingNames(); if (isUnboundVar(leftArg, bindingNames) || isUnboundVar(rightArg, bindingNames)) { // One or both var(s) are unbound, this expression will never // return any results filter.replaceWith(new EmptySet()); return; } Set<String> assuredBindingNames = filterArg.getAssuredBindingNames(); if (isUnboundVar(leftArg, assuredBindingNames) || isUnboundVar(rightArg, assuredBindingNames)) { // One or both var(s) are potentially unbound, inlining could // invalidate the result e.g. in case of left joins return; } if (leftArg instanceof Var || rightArg instanceof Var) { if (filterArg instanceof ArbitraryLengthPath && leftArg instanceof Var && rightArg instanceof Var) { final ArbitraryLengthPath alp = (ArbitraryLengthPath) filterArg; final List<Var> sameTermArgs = Arrays.asList((Var) leftArg, (Var) rightArg); if (sameTermArgs.contains(alp.getSubjectVar()) && sameTermArgs.contains(alp.getObjectVar())) { // SameTerm provides a deferred mapping to allow arbitrary-length property path to produce // cyclic paths. See SES-1685. // we can not inline. return; } } BindingSetAssignmentCollector collector = new BindingSetAssignmentCollector(); filterArg.visit(collector); for (BindingSetAssignment bsa : collector.getBindingSetAssignments()) { // check if the VALUES clause / bindingsetassignment contains // one of the arguments of the sameTerm. // if so, we can not inline. Set<String> names = bsa.getAssuredBindingNames(); if (leftArg instanceof Var) { if (names.contains(((Var) leftArg).getName())) { return; } } if (rightArg instanceof Var) { if (names.contains(((Var) rightArg).getName())) { return; } } } } Value leftValue = getValue(leftArg); Value rightValue = getValue(rightArg); if (leftValue != null && rightValue != null) { // ConstantOptimizer should have taken care of this } else if (leftValue != null && rightArg instanceof Var) { bindVar((Var) rightArg, leftValue, filter); } else if (rightValue != null && leftArg instanceof Var) { bindVar((Var) leftArg, rightValue, filter); } else if (leftArg instanceof Var && rightArg instanceof Var) { // Two unbound variables, rename rightArg to leftArg renameVar((Var) rightArg, (Var) leftArg, filter); } } }
Example #29
Source File: AbstractQueryModelVisitor.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void meet(EmptySet node) throws X { meetNode(node); }
Example #30
Source File: HalyardEvaluationStatistics.java From Halyard with Apache License 2.0 | 4 votes |
@Override public void meet(EmptySet node) { super.meet(node); updateMap(node); }