Java Code Examples for org.eclipse.rdf4j.query.algebra.LeftJoin#getCondition()

The following examples show how to use org.eclipse.rdf4j.query.algebra.LeftJoin#getCondition() . 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: PrepareOwnedTupleExpr.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void meet(LeftJoin node) throws RepositoryException {
	if (node.getCondition() == null) {
		Map<String, String> vars = new HashMap<>();
		StringBuilder builder = new StringBuilder();
		node.getLeftArg().visit(this);
		if (patternNode != null) {
			builder.append(pattern);
			vars.putAll(variables);
			node.getRightArg().visit(this);
			if (patternNode != null) {
				builder.append("OPTIONAL {").append(pattern).append("}\n");
				vars.putAll(variables);
				this.variables = vars;
				this.pattern = builder.toString();
				this.patternNode = node;
			}
		}
	} else {
		super.meet(node);
	}
}
 
Example 2
Source File: FilterFunctionOptimizer.java    From rya with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 3
Source File: GeoEnabledFilterFunctionOptimizer.java    From rya with Apache License 2.0 6 votes vote down vote up
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, fVisitor.args.get(i)));
    }
    removeMatchedPattern(tupleExpr, matchStatement, new IndexerExprReplacer(results));
}
 
Example 4
Source File: QueryModelPruner.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 5
Source File: QueryModelPruner.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 6
Source File: QueryModelNormalizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 7
Source File: SparqlTupleExprRenderer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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);
}
 
Example 8
Source File: FlattenedOptional.java    From rya with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 9
Source File: SPARQLTupleExprRenderer.java    From semagrow with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example 10
Source File: FedXLeftJoin.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public FedXLeftJoin(LeftJoin leftJoin, QueryInfo queryInfo) {
	super(leftJoin.getLeftArg(), leftJoin.getRightArg(), leftJoin.getCondition());
	this.queryInfo = queryInfo;
}
 
Example 11
Source File: SerqlTupleExprRenderer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @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("], ");
}