use of org.eclipse.rdf4j.query.algebra.Modify in project rdf4j by eclipse.
the class UpdateExprBuilder method visit.
@Override
public Modify visit(ASTDeleteWhere node, Object data) throws VisitorException {
// Collect delete clause triples
GraphPattern parentGP = graphPattern;
graphPattern = new GraphPattern();
// inherit scope & context
graphPattern.setStatementPatternScope(parentGP.getStatementPatternScope());
graphPattern.setContextVar(parentGP.getContextVar());
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
node.jjtGetChild(i).jjtAccept(this, data);
}
TupleExpr whereExpr = graphPattern.buildTupleExpr();
graphPattern = parentGP;
TupleExpr deleteExpr = whereExpr.clone();
// FIXME we should adapt the grammar so we can avoid doing this
// post-processing.
VarCollector collector = new VarCollector();
deleteExpr.visit(collector);
for (Var var : collector.getCollectedVars()) {
if (var.isAnonymous() && !var.hasValue()) {
throw new VisitorException("DELETE WHERE may not contain blank nodes");
}
}
Modify modify = new Modify(deleteExpr, null, whereExpr);
return modify;
}
use of org.eclipse.rdf4j.query.algebra.Modify 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.Modify in project rdf4j by eclipse.
the class UpdateExprBuilder method visit.
@Override
public Modify visit(ASTModify node, Object data) throws VisitorException {
ASTWhereClause whereClause = node.getWhereClause();
TupleExpr where = null;
if (whereClause != null) {
where = (TupleExpr) whereClause.jjtAccept(this, data);
}
TupleExpr delete = null;
ASTDeleteClause deleteNode = node.getDeleteClause();
if (deleteNode != null) {
delete = (TupleExpr) deleteNode.jjtAccept(this, data);
}
TupleExpr insert = null;
ASTInsertClause insertNode = node.getInsertClause();
if (insertNode != null) {
insert = (TupleExpr) insertNode.jjtAccept(this, data);
}
Modify modifyExpr = new Modify(delete, insert, where);
return modifyExpr;
}
Aggregations