use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public TupleExpr visit(ASTGraphMinus node, Object data) throws VisitorException {
TupleExpr leftArg = (TupleExpr) node.getLeftArg().jjtAccept(this, null);
TupleExpr rightArg = (TupleExpr) node.getRightArg().jjtAccept(this, null);
return new Difference(leftArg, rightArg);
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public TupleExpr visit(ASTTupleMinus node, Object data) throws VisitorException {
TupleExpr leftArg = (TupleExpr) node.getLeftArg().jjtAccept(this, null);
TupleExpr rightArg = (TupleExpr) node.getRightArg().jjtAccept(this, null);
return new Difference(leftArg, rightArg);
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public TupleExpr visit(ASTConstructQuery node, Object data) throws VisitorException {
TupleExpr tupleExpr;
if (node.hasQueryBody()) {
// Build tuple expression for query body
tupleExpr = (TupleExpr) node.getQueryBody().jjtAccept(this, null);
} else {
tupleExpr = new SingletonSet();
}
// Apply result ordering
ASTOrderBy orderByNode = node.getOrderBy();
if (orderByNode != null) {
List<OrderElem> orderElemements = (List<OrderElem>) orderByNode.jjtAccept(this, null);
tupleExpr = new Order(tupleExpr, orderElemements);
}
// Create constructor
ConstructorBuilder cb = new ConstructorBuilder();
ASTConstruct constructNode = node.getConstructClause();
if (!constructNode.isWildcard()) {
TupleExpr constructExpr = (TupleExpr) constructNode.jjtAccept(this, null);
tupleExpr = cb.buildConstructor(tupleExpr, constructExpr, constructNode.isDistinct(), constructNode.isReduced());
} else if (node.hasQueryBody()) {
tupleExpr = cb.buildConstructor(tupleExpr, constructNode.isDistinct(), constructNode.isReduced());
}
// else: "construct *" without query body, just return the SingletonSet
// process limit and offset clauses, if present.
ASTLimit limitNode = node.getLimit();
int limit = -1;
if (limitNode != null) {
limit = (Integer) limitNode.jjtAccept(this, null);
}
ASTOffset offsetNode = node.getOffset();
int offset = -1;
if (offsetNode != null) {
offset = (Integer) offsetNode.jjtAccept(this, null);
}
if (offset >= 1 || limit >= 0) {
tupleExpr = new Slice(tupleExpr, offset, limit);
}
return tupleExpr;
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public TupleExpr visit(ASTTupleUnion node, Object data) throws VisitorException {
TupleExpr leftArg = (TupleExpr) node.getLeftArg().jjtAccept(this, null);
TupleExpr rightArg = (TupleExpr) node.getRightArg().jjtAccept(this, null);
TupleExpr result = new Union(leftArg, rightArg);
if (node.isDistinct()) {
result = new Distinct(result);
}
return result;
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public TupleExpr visit(ASTSelect node, Object data) throws VisitorException {
TupleExpr result = (TupleExpr) data;
Extension extension = new Extension();
ProjectionElemList projElemList = new ProjectionElemList();
for (ASTProjectionElem projElemNode : node.getProjectionElemList()) {
ValueExpr valueExpr = (ValueExpr) projElemNode.getValueExpr().jjtAccept(this, null);
String alias = projElemNode.getAlias();
if (alias != null) {
// aliased projection element
extension.addElement(new ExtensionElem(valueExpr, alias));
projElemList.addElement(new ProjectionElem(alias));
} else if (valueExpr instanceof Var) {
// unaliased variable
Var projVar = (Var) valueExpr;
projElemList.addElement(new ProjectionElem(projVar.getName()));
} else {
throw new IllegalStateException("required alias for non-Var projection elements not found");
}
}
if (!extension.getElements().isEmpty()) {
extension.setArg(result);
result = extension;
}
result = new Projection(result, projElemList);
if (node.isDistinct()) {
result = new Distinct(result);
} else if (node.isReduced()) {
result = new Reduced(result);
}
return result;
}
Aggregations