Search in sources :

Example 1 with ASTConstruct

use of org.eclipse.rdf4j.query.parser.serql.ast.ASTConstruct 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;
}
Also used : Order(org.eclipse.rdf4j.query.algebra.Order) SingletonSet(org.eclipse.rdf4j.query.algebra.SingletonSet) OrderElem(org.eclipse.rdf4j.query.algebra.OrderElem) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ASTLimit(org.eclipse.rdf4j.query.parser.serql.ast.ASTLimit) Slice(org.eclipse.rdf4j.query.algebra.Slice) ASTInList(org.eclipse.rdf4j.query.parser.serql.ast.ASTInList) ArrayList(java.util.ArrayList) List(java.util.List) ProjectionElemList(org.eclipse.rdf4j.query.algebra.ProjectionElemList) ASTOffset(org.eclipse.rdf4j.query.parser.serql.ast.ASTOffset) ASTConstruct(org.eclipse.rdf4j.query.parser.serql.ast.ASTConstruct) ASTOrderBy(org.eclipse.rdf4j.query.parser.serql.ast.ASTOrderBy)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Order (org.eclipse.rdf4j.query.algebra.Order)1 OrderElem (org.eclipse.rdf4j.query.algebra.OrderElem)1 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)1 SingletonSet (org.eclipse.rdf4j.query.algebra.SingletonSet)1 Slice (org.eclipse.rdf4j.query.algebra.Slice)1 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)1 ASTConstruct (org.eclipse.rdf4j.query.parser.serql.ast.ASTConstruct)1 ASTInList (org.eclipse.rdf4j.query.parser.serql.ast.ASTInList)1 ASTLimit (org.eclipse.rdf4j.query.parser.serql.ast.ASTLimit)1 ASTOffset (org.eclipse.rdf4j.query.parser.serql.ast.ASTOffset)1 ASTOrderBy (org.eclipse.rdf4j.query.parser.serql.ast.ASTOrderBy)1