Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-5229: fix left bind join in FedX for single binding input #5230

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -953,10 +953,6 @@ public abstract CloseableIteration<BindingSet> evaluateGroupedCheck(
*/
public CloseableIteration<BindingSet> evaluateLeftBoundJoinStatementPattern(
StatementTupleExpr stmt, final List<BindingSet> bindings) throws QueryEvaluationException {
// we can omit the bound join handling
if (bindings.size() == 1) {
return evaluate(stmt, bindings.get(0));
}

FilterValueExpr filterExpr = null;
if (stmt instanceof FilterTuple) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.Set;

import org.eclipse.rdf4j.common.iteration.Iterations;
import org.eclipse.rdf4j.federated.endpoint.Endpoint;
import org.eclipse.rdf4j.federated.structures.SubQuery;
import org.eclipse.rdf4j.model.util.Values;
import org.eclipse.rdf4j.model.vocabulary.FOAF;
import org.eclipse.rdf4j.model.vocabulary.OWL;
Expand Down Expand Up @@ -339,4 +341,81 @@ public void test_leftBindJoin_emptyOptional(boolean bindLeftJoinOptimizationEnab
}
}

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void test_leftBindJoin_emptyLeftArgumentAsExclusiveGroup(boolean bindLeftJoinOptimizationEnabled)
throws Exception {

var endpoints = prepareTest(
Arrays.asList("/tests/basic/data_emptyStore.ttl", "/tests/basic/data_emptyStore.ttl"));

Repository repo1 = getRepository(1);
Repository repo2 = getRepository(2);

Repository fedxRepo = fedxRule.getRepository();

fedxRule.setConfig(config -> {
config.withBoundJoinBlockSize(10);
config.withEnableOptionalAsBindJoin(bindLeftJoinOptimizationEnabled);
});

// add a person
try (RepositoryConnection conn = repo1.getConnection()) {
var p = Values.iri("http://ex.com/p1");
var otherP = Values.iri("http://other.com/p1");
conn.add(p, OWL.SAMEAS, otherP);
}

// add name for person 1
try (RepositoryConnection conn = repo2.getConnection()) {
var otherP = Values.iri("http://other.com/p1");
conn.add(otherP, FOAF.NAME, Values.literal("Person 1"));
}

// mark that repo2 for some reason has foaf:age statements (e.g. old cache entry)
Endpoint repo2Endpoint = endpoints.get(1);
federationContext().getSourceSelectionCache()
.updateInformation(new SubQuery(null, FOAF.AGE, null), repo2Endpoint, true);

fedxRule.enableDebug();

try {
// run query which joins results from multiple repos
// the age does not exist for any person
try (RepositoryConnection conn = fedxRepo.getConnection()) {
String query = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"SELECT * WHERE { "
+ " ?person owl:sameAs ?otherPerson . "
+ " OPTIONAL { ?otherPerson foaf:age ?age . } " // age does not exist, however is marked as
// ExclusiveStatement
+ "}";

TupleQuery tupleQuery = conn.prepareTupleQuery(query);
try (TupleQueryResult tqr = tupleQuery.evaluate()) {
var bindings = Iterations.asList(tqr);

Assertions.assertEquals(1, bindings.size());

for (int i = 1; i <= 1; i++) {
var p = Values.iri("http://ex.com/p" + i);
var otherP = Values.iri("http://other.com/p" + i);

// find the bindingset for the person in the unordered result
BindingSet bs = bindings.stream()
.filter(b -> b.getValue("person").equals(p))
.findFirst()
.orElseThrow();

Assertions.assertEquals(otherP, bs.getValue("otherPerson"));

Assertions.assertEquals(otherP, bs.getValue("otherPerson"));
Assertions.assertFalse(bs.hasBinding("age"));
}
}
}

} finally {
fedxRepo.shutDown();
}
}
}
Loading