Search in sources :

Example 1 with TupleExpr

use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.

the class GraphPattern method addOptionalTE.

public void addOptionalTE(GraphPattern gp) {
    List<ValueExpr> constraints = gp.removeAllConstraints();
    TupleExpr tupleExpr = gp.buildTupleExpr();
    OptionalTupleExpr optTE;
    if (constraints.isEmpty()) {
        optTE = new OptionalTupleExpr(tupleExpr);
    } else {
        ValueExpr constraint = constraints.get(0);
        for (int i = 1; i < constraints.size(); i++) {
            constraint = new And(constraint, constraints.get(i));
        }
        optTE = new OptionalTupleExpr(tupleExpr, constraint);
    }
    optionalTEs.add(optTE);
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) And(org.eclipse.rdf4j.query.algebra.And) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 2 with TupleExpr

use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public TupleExpr visit(ASTSelectQuery node, Object data) throws VisitorException {
    TupleExpr tupleExpr;
    ASTQueryBody queryBodyNode = node.getQueryBody();
    if (queryBodyNode != null) {
        // Build tuple expression for query body
        tupleExpr = (TupleExpr) queryBodyNode.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);
    }
    // Apply projection
    tupleExpr = (TupleExpr) node.getSelectClause().jjtAccept(this, tupleExpr);
    // 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) ASTLimit(org.eclipse.rdf4j.query.parser.serql.ast.ASTLimit) SingletonSet(org.eclipse.rdf4j.query.algebra.SingletonSet) Slice(org.eclipse.rdf4j.query.algebra.Slice) ASTQueryBody(org.eclipse.rdf4j.query.parser.serql.ast.ASTQueryBody) OrderElem(org.eclipse.rdf4j.query.algebra.OrderElem) 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) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ASTOrderBy(org.eclipse.rdf4j.query.parser.serql.ast.ASTOrderBy)

Example 3 with TupleExpr

use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public CompareAny visit(ASTCompareAny node, Object data) throws VisitorException {
    ValueExpr valueExpr = (ValueExpr) node.getLeftOperand().jjtAccept(this, null);
    TupleExpr tupleExpr = (TupleExpr) node.getRightOperand().jjtAccept(this, null);
    CompareOp op = node.getOperator().getValue();
    return new CompareAny(valueExpr, tupleExpr, op);
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) CompareOp(org.eclipse.rdf4j.query.algebra.Compare.CompareOp) CompareAny(org.eclipse.rdf4j.query.algebra.CompareAny) ASTCompareAny(org.eclipse.rdf4j.query.parser.serql.ast.ASTCompareAny) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 4 with TupleExpr

use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public TupleExpr visit(ASTTupleIntersect node, Object data) throws VisitorException {
    TupleExpr leftArg = (TupleExpr) node.getLeftArg().jjtAccept(this, null);
    TupleExpr rightArg = (TupleExpr) node.getRightArg().jjtAccept(this, null);
    return new Intersection(leftArg, rightArg);
}
Also used : Intersection(org.eclipse.rdf4j.query.algebra.Intersection) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 5 with TupleExpr

use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public In visit(ASTIn node, Object data) throws VisitorException {
    ValueExpr valueExpr = (ValueExpr) node.getLeftOperand().jjtAccept(this, null);
    TupleExpr tupleExpr = (TupleExpr) node.getRightOperand().jjtAccept(this, null);
    return new In(valueExpr, tupleExpr);
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) In(org.eclipse.rdf4j.query.algebra.In) ASTIn(org.eclipse.rdf4j.query.parser.serql.ast.ASTIn) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

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