Search in sources :

Example 16 with TupleExpr

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

the class TupleExprBuilder method visit.

@Override
public Object visit(ASTOptionalGraphPattern node, Object data) throws VisitorException {
    GraphPattern parentGP = graphPattern;
    graphPattern = new GraphPattern(parentGP);
    super.visit(node, null);
    // remove filter conditions from graph pattern for inclusion as
    // conditions
    // in the OptionalTE
    List<ValueExpr> optionalConstraints = graphPattern.removeAllConstraints();
    TupleExpr optional = graphPattern.buildTupleExpr();
    graphPattern = parentGP;
    graphPattern.addOptionalTE(optional, optionalConstraints);
    return null;
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 17 with TupleExpr

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

Example 18 with TupleExpr

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

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

the class SPARQLParserTest method testParseWildcardSubselectInUpdate.

/**
 * Verify that an INSERT with a subselect using a wildcard correctly adds vars to projection
 * @see <a href="https://github.com/eclipse/rdf4j/issues/686">#686</a>
 */
@Test
public void testParseWildcardSubselectInUpdate() throws Exception {
    StringBuilder update = new StringBuilder();
    update.append("INSERT { <urn:a> <urn:b> <urn:c> . } WHERE { SELECT * {?s ?p ?o } }");
    ParsedUpdate parsedUpdate = parser.parseUpdate(update.toString(), null);
    List<UpdateExpr> exprs = parsedUpdate.getUpdateExprs();
    assertEquals(1, exprs.size());
    UpdateExpr expr = exprs.get(0);
    assertTrue(expr instanceof Modify);
    Modify m = (Modify) expr;
    TupleExpr whereClause = m.getWhereExpr();
    assertTrue(whereClause instanceof Projection);
    ProjectionElemList projectionElemList = ((Projection) whereClause).getProjectionElemList();
    assertNotNull(projectionElemList);
    List<ProjectionElem> elements = projectionElemList.getElements();
    assertNotNull(elements);
    assertEquals("projection should contain all three variables", 3, elements.size());
}
Also used : ProjectionElemList(org.eclipse.rdf4j.query.algebra.ProjectionElemList) ParsedUpdate(org.eclipse.rdf4j.query.parser.ParsedUpdate) UpdateExpr(org.eclipse.rdf4j.query.algebra.UpdateExpr) Projection(org.eclipse.rdf4j.query.algebra.Projection) Modify(org.eclipse.rdf4j.query.algebra.Modify) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ProjectionElem(org.eclipse.rdf4j.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 20 with TupleExpr

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

the class SPARQLParserTest method testOrderByWithAliases1.

@Test
public void testOrderByWithAliases1() throws Exception {
    String queryString = " SELECT ?x (SUM(?v1)/COUNT(?v1) as ?r) WHERE { ?x <urn:foo> ?v1 } GROUP BY ?x ORDER BY ?r";
    ParsedQuery query = parser.parseQuery(queryString, null);
    assertNotNull(query);
    TupleExpr te = query.getTupleExpr();
    assertTrue(te instanceof Projection);
    te = ((Projection) te).getArg();
    assertTrue(te instanceof Order);
    te = ((Order) te).getArg();
    assertTrue(te instanceof Extension);
}
Also used : Order(org.eclipse.rdf4j.query.algebra.Order) Extension(org.eclipse.rdf4j.query.algebra.Extension) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) Projection(org.eclipse.rdf4j.query.algebra.Projection) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Test(org.junit.Test)

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