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;
}
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());
}
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());
}
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());
}
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);
}
Aggregations