Search in sources :

Example 1 with Slice

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

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

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

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

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

the class SPARQLParserTest method testSES1927UnequalLiteralValueConstants2.

@Test
public void testSES1927UnequalLiteralValueConstants2() throws Exception {
    StringBuilder qb = new StringBuilder();
    qb.append("ASK {?a <foo:bar> \"test\". ?a <foo:foo> \"test\"^^<foo:bar> .} ");
    ParsedQuery q = parser.parseQuery(qb.toString(), null);
    TupleExpr te = q.getTupleExpr();
    assertNotNull(te);
    assertTrue(te instanceof Slice);
    Slice s = (Slice) te;
    assertTrue(s.getArg() instanceof Join);
    Join j = (Join) s.getArg();
    assertTrue(j.getLeftArg() instanceof StatementPattern);
    assertTrue(j.getRightArg() instanceof StatementPattern);
    StatementPattern leftArg = (StatementPattern) j.getLeftArg();
    StatementPattern rightArg = (StatementPattern) j.getRightArg();
    assertFalse(leftArg.getObjectVar().equals(rightArg.getObjectVar()));
    assertNotEquals(leftArg.getObjectVar().getName(), rightArg.getObjectVar().getName());
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) Slice(org.eclipse.rdf4j.query.algebra.Slice) Join(org.eclipse.rdf4j.query.algebra.Join) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Test(org.junit.Test)

Aggregations

Slice (org.eclipse.rdf4j.query.algebra.Slice)11 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)11 Join (org.eclipse.rdf4j.query.algebra.Join)6 Group (org.eclipse.rdf4j.query.algebra.Group)4 Test (org.junit.Test)4 BindingSetAssignment (org.eclipse.rdf4j.query.algebra.BindingSetAssignment)3 Order (org.eclipse.rdf4j.query.algebra.Order)3 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)3 ParsedQuery (org.eclipse.rdf4j.query.parser.ParsedQuery)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OrderElem (org.eclipse.rdf4j.query.algebra.OrderElem)2 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)2 SingletonSet (org.eclipse.rdf4j.query.algebra.SingletonSet)2 ASTInList (org.eclipse.rdf4j.query.parser.serql.ast.ASTInList)2 ASTLimit (org.eclipse.rdf4j.query.parser.serql.ast.ASTLimit)2 ASTOffset (org.eclipse.rdf4j.query.parser.serql.ast.ASTOffset)2 ASTOrderBy (org.eclipse.rdf4j.query.parser.serql.ast.ASTOrderBy)2 IRI (org.eclipse.rdf4j.model.IRI)1 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)1