Search in sources :

Example 6 with TupleExpr

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

the class QueryModelBuilder method visit.

@Override
public Object visit(ASTPathExprUnion node, Object data) throws VisitorException {
    Iterator<ASTPathExpr> args = node.getPathExprList().iterator();
    // Create new sub-graph pattern for optional path expressions
    TupleExpr unionExpr = parseGraphPattern(args.next()).buildTupleExpr();
    while (args.hasNext()) {
        TupleExpr argExpr = parseGraphPattern(args.next()).buildTupleExpr();
        unionExpr = new Union(unionExpr, argExpr);
    }
    graphPattern.addRequiredTE(unionExpr);
    return null;
}
Also used : ASTPathExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTPathExpr) 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 TupleExpr

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

the class TupleExprBuilder method visit.

@Override
public Group visit(ASTGroupClause node, Object data) throws VisitorException {
    TupleExpr tupleExpr = (TupleExpr) data;
    Group g = new Group(tupleExpr);
    int childCount = node.jjtGetNumChildren();
    List<String> groupBindingNames = new ArrayList<String>();
    for (int i = 0; i < childCount; i++) {
        String name = (String) node.jjtGetChild(i).jjtAccept(this, g);
        groupBindingNames.add(name);
    }
    g.setGroupBindingNames(groupBindingNames);
    return g;
}
Also used : Group(org.eclipse.rdf4j.query.algebra.Group) ArrayList(java.util.ArrayList) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 8 with TupleExpr

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

the class TupleExprBuilder method visit.

@Override
public TupleExpr visit(ASTDescribeQuery node, Object data) throws VisitorException {
    TupleExpr tupleExpr = null;
    if (node.getWhereClause() != null) {
        // Start with building the graph pattern
        graphPattern = new GraphPattern();
        node.getWhereClause().jjtAccept(this, null);
        tupleExpr = graphPattern.buildTupleExpr();
        // Apply grouping
        Group group = null;
        ASTGroupClause groupNode = node.getGroupClause();
        if (groupNode != null) {
            tupleExpr = (TupleExpr) groupNode.jjtAccept(this, tupleExpr);
            group = (Group) tupleExpr;
        }
        if (node.getHavingClause() != null) {
            if (group == null) {
                // create implicit group
                group = new Group(tupleExpr);
            }
            // Apply HAVING group filter condition
            tupleExpr = processHavingClause(node.getHavingClause(), tupleExpr, group);
        }
        if (node.getOrderClause() != null) {
            if (group == null) {
                // create implicit group
                group = new Group(tupleExpr);
            }
            // Apply result ordering
            tupleExpr = processOrderClause(node.getOrderClause(), tupleExpr, group);
        }
        // Process limit and offset clauses
        ASTLimit limitNode = node.getLimit();
        long limit = -1;
        if (limitNode != null) {
            limit = (Long) limitNode.jjtAccept(this, null);
        }
        ASTOffset offsetNode = node.getOffset();
        long offset = -1;
        if (offsetNode != null) {
            offset = (Long) offsetNode.jjtAccept(this, null);
        }
        if (offset >= 1 || limit >= 0) {
            tupleExpr = new Slice(tupleExpr, offset, limit);
        }
    }
    // Process describe clause last
    return (TupleExpr) node.getDescribe().jjtAccept(this, tupleExpr);
}
Also used : Group(org.eclipse.rdf4j.query.algebra.Group) Slice(org.eclipse.rdf4j.query.algebra.Slice) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 9 with TupleExpr

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

the class TupleExprBuilder method visit.

@Override
public String visit(ASTGroupCondition node, Object data) throws VisitorException {
    Group group = (Group) data;
    TupleExpr arg = group.getArg();
    Extension extension = null;
    if (arg instanceof Extension) {
        extension = (Extension) arg;
    } else {
        extension = new Extension();
    }
    String name = null;
    ValueExpr ve = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, data);
    boolean aliased = false;
    if (node.jjtGetNumChildren() > 1) {
        aliased = true;
        Var v = (Var) node.jjtGetChild(1).jjtAccept(this, data);
        name = v.getName();
    } else {
        if (ve instanceof Var) {
            name = ((Var) ve).getName();
        } else {
            aliased = true;
            Var v = createAnonVar();
            name = v.getName();
        }
    }
    if (aliased) {
        ExtensionElem elem = new ExtensionElem(ve, name);
        extension.addElement(elem);
    }
    if (extension.getElements().size() > 0 && !(arg instanceof Extension)) {
        extension.setArg(arg);
        group.setArg(extension);
    }
    return name;
}
Also used : Extension(org.eclipse.rdf4j.query.algebra.Extension) Group(org.eclipse.rdf4j.query.algebra.Group) ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) Var(org.eclipse.rdf4j.query.algebra.Var) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 10 with TupleExpr

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

the class TupleExprBuilder method visit.

@Override
public TupleExpr visit(ASTSelectQuery node, Object data) throws VisitorException {
    GraphPattern parentGP = graphPattern;
    // Start with building the graph pattern
    graphPattern = new GraphPattern(parentGP);
    node.getWhereClause().jjtAccept(this, null);
    TupleExpr tupleExpr = graphPattern.buildTupleExpr();
    // Apply grouping
    Group group = null;
    ASTGroupClause groupNode = node.getGroupClause();
    if (groupNode != null) {
        tupleExpr = (TupleExpr) groupNode.jjtAccept(this, tupleExpr);
        group = (Group) tupleExpr;
    }
    final ASTHavingClause havingClause = node.getHavingClause();
    if (havingClause != null) {
        if (group == null) {
            // create implicit group
            group = new Group(tupleExpr);
        }
        // Apply HAVING group filter condition
        tupleExpr = processHavingClause(havingClause, tupleExpr, group);
    }
    // process bindings clause
    final ASTBindingsClause bindingsClause = node.getBindingsClause();
    if (bindingsClause != null) {
        tupleExpr = new Join((BindingSetAssignment) bindingsClause.jjtAccept(this, null), tupleExpr);
    }
    final ASTOrderClause orderClause = node.getOrderClause();
    if (orderClause != null) {
        if (group == null) {
            // create implicit group
            group = new Group(tupleExpr);
        }
        // Apply result ordering
        tupleExpr = processOrderClause(node.getOrderClause(), tupleExpr, group);
    }
    // Apply projection
    tupleExpr = (TupleExpr) node.getSelect().jjtAccept(this, tupleExpr);
    // Process limit and offset clauses
    ASTLimit limitNode = node.getLimit();
    long limit = -1L;
    if (limitNode != null) {
        limit = (Long) limitNode.jjtAccept(this, null);
    }
    ASTOffset offsetNode = node.getOffset();
    long offset = -1L;
    if (offsetNode != null) {
        offset = (Long) offsetNode.jjtAccept(this, null);
    }
    if (offset >= 1L || limit >= 0L) {
        tupleExpr = new Slice(tupleExpr, offset, limit);
    }
    if (parentGP != null) {
        parentGP.addRequiredTE(tupleExpr);
        graphPattern = parentGP;
    }
    return tupleExpr;
}
Also used : Group(org.eclipse.rdf4j.query.algebra.Group) BindingSetAssignment(org.eclipse.rdf4j.query.algebra.BindingSetAssignment) Join(org.eclipse.rdf4j.query.algebra.Join) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Slice(org.eclipse.rdf4j.query.algebra.Slice)

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