Skip to content

Commit

Permalink
GH-4815 retrieve the variable names from BindingSetAssignment nodes w…
Browse files Browse the repository at this point in the history
…hen making the list of names to include in the ArrayBindingSet (#4816)
  • Loading branch information
hmottestad authored Oct 18, 2023
2 parents b766d18 + 94f5b25 commit 2c64c26
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.rdf4j.query.Dataset;
import org.eclipse.rdf4j.query.MutableBindingSet;
import org.eclipse.rdf4j.query.QueryEvaluationException;
import org.eclipse.rdf4j.query.algebra.BindingSetAssignment;
import org.eclipse.rdf4j.query.algebra.ExtensionElem;
import org.eclipse.rdf4j.query.algebra.Group;
import org.eclipse.rdf4j.query.algebra.MultiProjection;
Expand Down Expand Up @@ -307,6 +308,19 @@ public void meet(ExtensionElem node) throws QueryEvaluationException {
super.meet(node);
}

@Override
public void meet(BindingSetAssignment node) throws QueryEvaluationException {
Set<String> bindingNames = node.getBindingNames();

Set<String> collect = bindingNames.stream()
.map(varName -> varNames.computeIfAbsent(varName, k -> k))
.collect(Collectors.toSet());

node.setBindingNames(collect);

super.meet(node);
}

@Override
public void meet(Group node) throws QueryEvaluationException {
List<String> collect = node.getGroupBindingNames()
Expand All @@ -316,6 +330,7 @@ public void meet(Group node) throws QueryEvaluationException {
node.setGroupBindingNames(collect);
super.meet(node);
}

};
node.visit(queryModelVisitorBase);
return varNames.keySet().toArray(new String[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.rdf4j.query.QueryResults;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.query.Update;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.testsuite.sparql.AbstractComplianceTest;
import org.junit.Test;
Expand All @@ -41,7 +42,6 @@
* Tests on SPARQL VALUES clauses.
*
* @author Jeen Broekstra
*
*/
public class ValuesTest extends AbstractComplianceTest {

Expand Down Expand Up @@ -204,4 +204,21 @@ public void testFilterExistsExternalValuesClause() {
assertEquals("single result expected", 1, result.size());
assertEquals("http://subj1", result.get(0).getValue("s").stringValue());
}

@Test
public void testMultipleValuesClauses() {
Update update = conn.prepareUpdate("PREFIX ex: <http://example.org/>\n" +
"\n" +
"INSERT DATA { ex:sub ex:somePred \"value\" . };\n" +
"\n" +
"INSERT { ?s ?newPred ?newObj }\n" +
"WHERE {\n" +
" # If one combines these into a single VALUES clause then it also works\n" +
" VALUES ?newPred { ex:somePred2 }\n" +
" VALUES ?newObj { \"value2\" }\n" +
" ?s ex:somePred [] .\n" +
"}");
update.execute();
}

}

0 comments on commit 2c64c26

Please sign in to comment.