use of org.eclipse.rdf4j.query.algebra.ExtensionElem in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public Object visit(ASTBind node, Object data) throws VisitorException {
// bind expression
ValueExpr ve = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, data);
// name to bind the expression outcome to
Node aliasNode = node.jjtGetChild(1);
String alias = ((ASTVar) aliasNode).getName();
Extension extension = new Extension();
extension.addElement(new ExtensionElem(ve, alias));
TupleExpr result = null;
TupleExpr arg = graphPattern.buildTupleExpr();
// check if alias is not previously used.
if (arg.getBindingNames().contains(alias)) {
// SES-2314 we need to doublecheck that the reused varname is not
// just
// for an anonymous var or a constant.
VarCollector collector = new VarCollector();
arg.visit(collector);
for (Var v : collector.getCollectedVars()) {
if (alias.equals(v.getName())) {
if (!v.isConstant() && !v.isAnonymous()) {
throw new VisitorException(String.format("BIND clause alias '%s' was previously used", alias));
}
break;
}
}
}
if (arg instanceof Filter) {
result = arg;
// the BIND expression.
while (((Filter) arg).getArg() instanceof Filter) {
arg = ((Filter) arg).getArg();
}
extension.setArg(((Filter) arg).getArg());
((Filter) arg).setArg(extension);
} else {
extension.setArg(arg);
result = extension;
}
GraphPattern replacementGP = new GraphPattern(graphPattern);
replacementGP.addRequiredTE(result);
graphPattern = replacementGP;
return result;
}
Aggregations