Search in sources :

Example 6 with Slice

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

the class SPARQLParserTest method testParsedBooleanQueryRootNode.

@Test
public void testParsedBooleanQueryRootNode() throws Exception {
    StringBuilder qb = new StringBuilder();
    qb.append("ASK {?a <foo:bar> \"test\"}");
    ParsedBooleanQuery q = (ParsedBooleanQuery) parser.parseQuery(qb.toString(), null);
    TupleExpr te = q.getTupleExpr();
    assertNotNull(te);
    assertTrue(te instanceof Slice);
    assertNull(te.getParentNode());
}
Also used : Slice(org.eclipse.rdf4j.query.algebra.Slice) ParsedBooleanQuery(org.eclipse.rdf4j.query.parser.ParsedBooleanQuery) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Test(org.junit.Test)

Example 7 with Slice

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

the class QueryModelBuilder method visit.

@Override
public TupleExpr visit(ASTConstructQuery node, Object data) throws VisitorException {
    TupleExpr tupleExpr;
    if (node.hasQueryBody()) {
        // Build tuple expression for query body
        tupleExpr = (TupleExpr) node.getQueryBody().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);
    }
    // Create constructor
    ConstructorBuilder cb = new ConstructorBuilder();
    ASTConstruct constructNode = node.getConstructClause();
    if (!constructNode.isWildcard()) {
        TupleExpr constructExpr = (TupleExpr) constructNode.jjtAccept(this, null);
        tupleExpr = cb.buildConstructor(tupleExpr, constructExpr, constructNode.isDistinct(), constructNode.isReduced());
    } else if (node.hasQueryBody()) {
        tupleExpr = cb.buildConstructor(tupleExpr, constructNode.isDistinct(), constructNode.isReduced());
    }
    // else: "construct *" without query body, just return the SingletonSet
    // 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) SingletonSet(org.eclipse.rdf4j.query.algebra.SingletonSet) OrderElem(org.eclipse.rdf4j.query.algebra.OrderElem) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ASTLimit(org.eclipse.rdf4j.query.parser.serql.ast.ASTLimit) Slice(org.eclipse.rdf4j.query.algebra.Slice) 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) ASTConstruct(org.eclipse.rdf4j.query.parser.serql.ast.ASTConstruct) ASTOrderBy(org.eclipse.rdf4j.query.parser.serql.ast.ASTOrderBy)

Example 8 with Slice

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

the class SPARQLParserTest method testSES1922PathSequenceWithValueConstant.

@Test
public void testSES1922PathSequenceWithValueConstant() throws Exception {
    StringBuilder qb = new StringBuilder();
    qb.append("ASK {?A (<foo:bar>)/<foo:foo> <foo:objValue>} ");
    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();
    assertTrue(leftArg.getObjectVar().equals(rightArg.getSubjectVar()));
    assertEquals(leftArg.getObjectVar().getName(), rightArg.getSubjectVar().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)

Example 9 with Slice

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

the class SPARQLParserTest method testSES1927UnequalLiteralValueConstants1.

@Test
public void testSES1927UnequalLiteralValueConstants1() throws Exception {
    StringBuilder qb = new StringBuilder();
    qb.append("ASK {?a <foo:bar> \"test\". ?a <foo:foo> \"test\"@en .} ");
    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)

Example 10 with Slice

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

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