Search in sources :

Example 36 with TupleExpr

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);
}
Also used : Difference(org.eclipse.rdf4j.query.algebra.Difference) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 37 with TupleExpr

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);
}
Also used : Difference(org.eclipse.rdf4j.query.algebra.Difference) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 38 with TupleExpr

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;
}
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)

Example 39 with 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;
}
Also used : Distinct(org.eclipse.rdf4j.query.algebra.Distinct) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ASTGraphUnion(org.eclipse.rdf4j.query.parser.serql.ast.ASTGraphUnion) Union(org.eclipse.rdf4j.query.algebra.Union) ASTPathExprUnion(org.eclipse.rdf4j.query.parser.serql.ast.ASTPathExprUnion) ASTTupleUnion(org.eclipse.rdf4j.query.parser.serql.ast.ASTTupleUnion)

Example 40 with TupleExpr

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;
}
Also used : ProjectionElemList(org.eclipse.rdf4j.query.algebra.ProjectionElemList) ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) ASTVar(org.eclipse.rdf4j.query.parser.serql.ast.ASTVar) Var(org.eclipse.rdf4j.query.algebra.Var) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem) Projection(org.eclipse.rdf4j.query.algebra.Projection) ASTString(org.eclipse.rdf4j.query.parser.serql.ast.ASTString) ASTProjectionElem(org.eclipse.rdf4j.query.parser.serql.ast.ASTProjectionElem) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Reduced(org.eclipse.rdf4j.query.algebra.Reduced) Extension(org.eclipse.rdf4j.query.algebra.Extension) Distinct(org.eclipse.rdf4j.query.algebra.Distinct) ProjectionElem(org.eclipse.rdf4j.query.algebra.ProjectionElem) ASTProjectionElem(org.eclipse.rdf4j.query.parser.serql.ast.ASTProjectionElem)

Aggregations

TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)61 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)19 Var (org.eclipse.rdf4j.query.algebra.Var)14 Projection (org.eclipse.rdf4j.query.algebra.Projection)13 Join (org.eclipse.rdf4j.query.algebra.Join)12 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)11 Slice (org.eclipse.rdf4j.query.algebra.Slice)11 ArrayList (java.util.ArrayList)9 Extension (org.eclipse.rdf4j.query.algebra.Extension)9 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)9 Test (org.junit.Test)9 Distinct (org.eclipse.rdf4j.query.algebra.Distinct)8 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)8 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)8 Filter (org.eclipse.rdf4j.query.algebra.Filter)7 Union (org.eclipse.rdf4j.query.algebra.Union)7 Group (org.eclipse.rdf4j.query.algebra.Group)6 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)6 Order (org.eclipse.rdf4j.query.algebra.Order)6 Reduced (org.eclipse.rdf4j.query.algebra.Reduced)6