Java Code Examples for org.eclipse.rdf4j.query.algebra.QueryModelNode#getParentNode()

The following examples show how to use org.eclipse.rdf4j.query.algebra.QueryModelNode#getParentNode() . 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: DistanceQuerySpec.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public QueryModelNode removeQueryPatterns() {
	final QueryModelNode placeholder = new SingletonSet();

	filter.replaceWith(filter.getArg());

	geoStatement.replaceWith(placeholder);

	QueryModelNode functionParent = distanceFunction.getParentNode();
	if (functionParent instanceof ExtensionElem) {
		Extension extension = (Extension) functionParent.getParentNode();
		List<ExtensionElem> elements = extension.getElements();
		if (elements.size() > 1) {
			elements.remove(functionParent);
		} else {
			extension.replaceWith(extension.getArg());
		}
	}

	return placeholder;
}
 
Example 2
Source File: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the limit of the current variable bindings before any further projection.
 */
protected long getLimit(QueryModelNode node) {
	long offset = 0;
	if (node instanceof Slice) {
		Slice slice = (Slice) node;
		if (slice.hasOffset() && slice.hasLimit()) {
			return slice.getOffset() + slice.getLimit();
		} else if (slice.hasLimit()) {
			return slice.getLimit();
		} else if (slice.hasOffset()) {
			offset = slice.getOffset();
		}
	}
	QueryModelNode parent = node.getParentNode();
	if (parent instanceof Distinct || parent instanceof Reduced || parent instanceof Slice) {
		long limit = getLimit(parent);
		if (offset > 0L && limit < Long.MAX_VALUE) {
			return offset + limit;
		} else {
			return limit;
		}
	}
	return Long.MAX_VALUE;
}
 
Example 3
Source File: HalyardTupleExprEvaluation.java    From Halyard with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the limit of the current variable bindings before any further projection.
 */
private static long getLimit(QueryModelNode node) {
    long offset = 0;
    if (node instanceof Slice) {
        Slice slice = (Slice) node;
        if (slice.hasOffset() && slice.hasLimit()) {
            return slice.getOffset() + slice.getLimit();
        } else if (slice.hasLimit()) {
            return slice.getLimit();
        } else if (slice.hasOffset()) {
            offset = slice.getOffset();
        }
    }
    QueryModelNode parent = node.getParentNode();
    if (parent instanceof Distinct || parent instanceof Reduced || parent instanceof Slice) {
        long limit = getLimit(parent);
        if (offset > 0L && limit < Long.MAX_VALUE) {
            return offset + limit;
        } else {
            return limit;
        }
    }
    return Long.MAX_VALUE;
}
 
Example 4
Source File: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected boolean isReducedOrDistinct(QueryModelNode node) {
	QueryModelNode parent = node.getParentNode();
	if (parent instanceof Slice) {
		return isReducedOrDistinct(parent);
	}
	return parent instanceof Distinct || parent instanceof Reduced;
}
 
Example 5
Source File: QueryModelNormalizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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();
}
 
Example 6
Source File: ProjectionIterator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private final boolean determineOuterProjection() {
	QueryModelNode ancestor = projection;
	while (ancestor.getParentNode() != null) {
		ancestor = ancestor.getParentNode();
		if (ancestor instanceof Projection || ancestor instanceof MultiProjection) {
			return false;
		}
	}
	return true;
}
 
Example 7
Source File: FilterIterator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean isPartOfSubQuery(QueryModelNode node) {
	if (node instanceof SubQueryValueOperator) {
		return true;
	}

	QueryModelNode parent = node.getParentNode();
	if (parent == null) {
		return false;
	} else {
		return isPartOfSubQuery(parent);
	}
}
 
Example 8
Source File: HalyardTupleExprEvaluation.java    From Halyard with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if the parent of the node is an instance of {@link Distinct} or {@link Reduced}.
 * @param node the {@link QueryModelNode} to test
 * @return {@code true} if the parent is and instance of {@link Distinct} or {@link Reduced} and {@code false} otherwise. If the parent is
 * an instance of {@link Slice} then the parent is considered to be the first non-{@code Slice} node up the tree.
 */
private static boolean isReducedOrDistinct(QueryModelNode node) {
    QueryModelNode parent = node.getParentNode();
    if (parent instanceof Slice) {
        return isReducedOrDistinct(parent);
    }
    return parent instanceof Distinct || parent instanceof Reduced;
}
 
Example 9
Source File: HalyardTupleExprEvaluation.java    From Halyard with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if a {@link QueryModelNode} is a {@link SubQueryValueOperator} or if it's parent node is
 * @param node
 * @return
 */
private boolean isPartOfSubQuery(QueryModelNode node) {
    if (node instanceof SubQueryValueOperator) {
        return true;
    }
    QueryModelNode parent = node.getParentNode();
    if (parent == null) {
        return false;
    } else {
        return isPartOfSubQuery(parent);
    }
}
 
Example 10
Source File: TopologyFactory.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
Source File: DistanceQuerySpecBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static boolean isChildOf(QueryModelNode child, QueryModelNode parent) {
	if (child.getParentNode() == parent) {
		return true;
	}
	return isChildOf(child.getParentNode(), parent);
}
 
Example 12
Source File: GeoRelationQuerySpecBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static boolean isChildOf(QueryModelNode child, QueryModelNode parent) {
	if (child.getParentNode() == parent) {
		return true;
	}
	return isChildOf(child.getParentNode(), parent);
}