Search in sources :

Example 6 with Union

use of org.eclipse.rdf4j.query.algebra.Union 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 7 with Union

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

the class TupleExprBuilder method visit.

@Override
public Object visit(ASTPathAlternative pathAltNode, Object data) throws VisitorException {
    int altCount = pathAltNode.jjtGetNumChildren();
    if (altCount > 1) {
        GraphPattern parentGP = graphPattern;
        Union union = new Union();
        Union currentUnion = union;
        for (int i = 0; i < altCount - 1; i++) {
            graphPattern = new GraphPattern(parentGP);
            pathAltNode.jjtGetChild(i).jjtAccept(this, data);
            TupleExpr arg = graphPattern.buildTupleExpr();
            currentUnion.setLeftArg(arg);
            if (i == altCount - 2) {
                // second-to-last item
                graphPattern = new GraphPattern(parentGP);
                pathAltNode.jjtGetChild(i + 1).jjtAccept(this, data);
                arg = graphPattern.buildTupleExpr();
                currentUnion.setRightArg(arg);
            } else {
                Union newUnion = new Union();
                currentUnion.setRightArg(newUnion);
                currentUnion = newUnion;
            }
        }
        parentGP.addRequiredTE(union);
        graphPattern = parentGP;
    } else {
        pathAltNode.jjtGetChild(0).jjtAccept(this, data);
    }
    return null;
}
Also used : Union(org.eclipse.rdf4j.query.algebra.Union) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Aggregations

TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)7 Union (org.eclipse.rdf4j.query.algebra.Union)7 Distinct (org.eclipse.rdf4j.query.algebra.Distinct)3 ASTGraphUnion (org.eclipse.rdf4j.query.parser.serql.ast.ASTGraphUnion)3 ASTPathExprUnion (org.eclipse.rdf4j.query.parser.serql.ast.ASTPathExprUnion)3 ASTTupleUnion (org.eclipse.rdf4j.query.parser.serql.ast.ASTTupleUnion)3 And (org.eclipse.rdf4j.query.algebra.And)1 ArbitraryLengthPath (org.eclipse.rdf4j.query.algebra.ArbitraryLengthPath)1 Compare (org.eclipse.rdf4j.query.algebra.Compare)1 Filter (org.eclipse.rdf4j.query.algebra.Filter)1 Join (org.eclipse.rdf4j.query.algebra.Join)1 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)1 Projection (org.eclipse.rdf4j.query.algebra.Projection)1 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)1 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)1 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)1 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)1 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)1 Var (org.eclipse.rdf4j.query.algebra.Var)1 ASTPathExpr (org.eclipse.rdf4j.query.parser.serql.ast.ASTPathExpr)1