Search in sources :

Example 1 with BindingSetAssignment

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

Example 2 with BindingSetAssignment

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

the class TupleExprBuilder method visit.

@Override
public BindingSetAssignment visit(ASTBindingsClause node, Object data) throws VisitorException {
    BindingSetAssignment bsa = new BindingSetAssignment();
    List<ASTVar> varNodes = node.jjtGetChildren(ASTVar.class);
    List<Var> vars = new ArrayList<Var>(varNodes.size());
    // preserve order in query
    Set<String> bindingNames = new LinkedHashSet<String>(varNodes.size());
    for (ASTVar varNode : varNodes) {
        Var var = (Var) varNode.jjtAccept(this, data);
        vars.add(var);
        bindingNames.add(var.getName());
    }
    bsa.setBindingNames(bindingNames);
    List<ASTBindingSet> bindingNodes = node.jjtGetChildren(ASTBindingSet.class);
    List<BindingSet> bindingSets = new ArrayList<BindingSet>(bindingNodes.size());
    for (ASTBindingSet bindingNode : bindingNodes) {
        BindingSet bindingSet = (BindingSet) bindingNode.jjtAccept(this, vars);
        bindingSets.add(bindingSet);
    }
    bsa.setBindingSets(bindingSets);
    return bsa;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) BindingSet(org.eclipse.rdf4j.query.BindingSet) BindingSetAssignment(org.eclipse.rdf4j.query.algebra.BindingSetAssignment) Var(org.eclipse.rdf4j.query.algebra.Var) ArrayList(java.util.ArrayList)

Example 3 with BindingSetAssignment

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

the class TupleExprBuilder method visit.

@Override
public TupleExpr visit(ASTConstructQuery node, Object data) throws VisitorException {
    // Start with building the graph pattern
    graphPattern = new GraphPattern();
    node.getWhereClause().jjtAccept(this, null);
    TupleExpr tupleExpr = graphPattern.buildTupleExpr();
    // Apply grouping
    ASTGroupClause groupNode = node.getGroupClause();
    if (groupNode != null) {
        tupleExpr = (TupleExpr) groupNode.jjtAccept(this, tupleExpr);
    }
    Group group = null;
    if (tupleExpr instanceof Group) {
        group = (Group) tupleExpr;
    } else {
        // create a new implicit group. Note that this group will only
        // actually
        // be used in the query model if the query has HAVING or ORDER BY
        // clause
        group = new Group(tupleExpr);
    }
    // Apply HAVING group filter condition
    tupleExpr = processHavingClause(node.getHavingClause(), tupleExpr, group);
    // process bindings clause
    ASTBindingsClause bindingsClause = node.getBindingsClause();
    if (bindingsClause != null) {
        tupleExpr = new Join((BindingSetAssignment) bindingsClause.jjtAccept(this, null), tupleExpr);
    }
    // Apply result ordering
    tupleExpr = processOrderClause(node.getOrderClause(), tupleExpr, null);
    // Process construct clause
    ASTConstruct constructNode = node.getConstruct();
    if (!constructNode.isWildcard()) {
        tupleExpr = (TupleExpr) constructNode.jjtAccept(this, tupleExpr);
    } else {
        // create construct clause from graph pattern.
        ConstructorBuilder cb = new ConstructorBuilder();
        // possible future use.
        try {
            tupleExpr = cb.buildConstructor(tupleExpr, false, false);
        } catch (MalformedQueryException e) {
            throw new VisitorException(e.getMessage());
        }
    }
    // 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 = -1;
    if (offsetNode != null) {
        offset = (Long) offsetNode.jjtAccept(this, null);
    }
    if (offset >= 1 || limit >= 0) {
        tupleExpr = new Slice(tupleExpr, offset, limit);
    }
    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) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException)

Example 4 with BindingSetAssignment

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

the class TupleExprBuilder method visit.

@Override
public BindingSetAssignment visit(ASTInlineData node, Object data) throws VisitorException {
    BindingSetAssignment bsa = new BindingSetAssignment();
    List<ASTVar> varNodes = node.jjtGetChildren(ASTVar.class);
    List<Var> vars = new ArrayList<Var>(varNodes.size());
    // preserve order in query
    Set<String> bindingNames = new LinkedHashSet<String>(varNodes.size());
    for (ASTVar varNode : varNodes) {
        Var var = (Var) varNode.jjtAccept(this, data);
        vars.add(var);
        bindingNames.add(var.getName());
    }
    bsa.setBindingNames(bindingNames);
    List<ASTBindingSet> bindingNodes = node.jjtGetChildren(ASTBindingSet.class);
    List<BindingSet> bindingSets = new ArrayList<BindingSet>(bindingNodes.size());
    for (ASTBindingSet bindingNode : bindingNodes) {
        BindingSet bindingSet = (BindingSet) bindingNode.jjtAccept(this, vars);
        bindingSets.add(bindingSet);
    }
    bsa.setBindingSets(bindingSets);
    graphPattern.addRequiredTE(bsa);
    return bsa;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) BindingSet(org.eclipse.rdf4j.query.BindingSet) BindingSetAssignment(org.eclipse.rdf4j.query.algebra.BindingSetAssignment) Var(org.eclipse.rdf4j.query.algebra.Var) ArrayList(java.util.ArrayList)

Example 5 with BindingSetAssignment

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

the class TupleExprBuilder method visit.

@Override
public TupleExpr visit(ASTAskQuery node, Object data) throws VisitorException {
    graphPattern = new GraphPattern();
    super.visit(node, null);
    TupleExpr tupleExpr = graphPattern.buildTupleExpr();
    tupleExpr = new Slice(tupleExpr, 0, 1);
    // 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);
    }
    return tupleExpr;
}
Also used : Group(org.eclipse.rdf4j.query.algebra.Group) Slice(org.eclipse.rdf4j.query.algebra.Slice) BindingSetAssignment(org.eclipse.rdf4j.query.algebra.BindingSetAssignment) Join(org.eclipse.rdf4j.query.algebra.Join) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Aggregations

BindingSetAssignment (org.eclipse.rdf4j.query.algebra.BindingSetAssignment)5 Group (org.eclipse.rdf4j.query.algebra.Group)3 Join (org.eclipse.rdf4j.query.algebra.Join)3 Slice (org.eclipse.rdf4j.query.algebra.Slice)3 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 BindingSet (org.eclipse.rdf4j.query.BindingSet)2 Var (org.eclipse.rdf4j.query.algebra.Var)2 ListBindingSet (org.eclipse.rdf4j.query.impl.ListBindingSet)2 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)1