Skip to content

Commit a07c04f

Browse files
authored
GH-5247 LeftJoinIterator bugfix when using condition (#5248)
2 parents 311d2d9 + 148aa31 commit a07c04f

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/iterator/LeftJoinIterator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ protected BindingSet getNextElement() throws QueryEvaluationException {
175175
// Join failed, return left arg's bindings
176176
return leftBindings;
177177
}
178-
179-
return null;
180178
}
181179
} catch (NoSuchElementException ignore) {
182180
// probably, one of the iterations has been closed concurrently in

core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/optimizer/ConjunctiveConstraintSplitterOptimizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void meet(LeftJoin node) {
6969
super.meet(node);
7070

7171
if (node.getCondition() != null) {
72-
List<ValueExpr> conjunctiveConstraints = new ArrayList<>(16);
72+
List<ValueExpr> conjunctiveConstraints = new ArrayList<>();
7373
getConjunctiveConstraints(node.getCondition(), conjunctiveConstraints);
7474

7575
TupleExpr arg = node.getRightArg();

testsuites/repository/src/main/java/org/eclipse/rdf4j/testsuite/repository/TupleQueryResultTest.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.io.ByteArrayOutputStream;
1717
import java.io.IOException;
1818
import java.io.InputStream;
19+
import java.io.StringReader;
1920
import java.lang.ref.Reference;
2021
import java.lang.ref.WeakReference;
2122
import java.util.ArrayList;
@@ -324,4 +325,73 @@ public void testNotClosingResultThrowsException() {
324325
});
325326

326327
}
328+
329+
@Test
330+
public void testLeftJoinWithJoinCondition() throws IOException {
331+
332+
String data = "@prefix wdt: <http://www.wikidata.org/prop/direct/> .\n" +
333+
"@prefix wd: <http://www.wikidata.org/entity/> .\n" +
334+
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" +
335+
"@prefix wikibase: <http://wikiba.se/ontology#> .\n" +
336+
337+
"\n" +
338+
"wd:other1 wdt:P106 wd:Q27532438 .\n" +
339+
"wd:other2 wdt:P106 wd:Q27532438 .\n" +
340+
"wd:other3 wdt:P106 wd:Q27532438 .\n" +
341+
342+
"wd:Q27532438 a wikibase:Item;\n" +
343+
" rdfs:label \"suffragist\"@en, \"sufrageto\"@eo, \"суфражистка\"@ru, \"suffragetti\"@fi, \"szüfrazsett\"@lv.\n"
344+
+
345+
346+
"wd:Q38203 wdt:P106 wd:Q27532437 .\n" +
347+
"\n" +
348+
"wd:Q27532437 a wikibase:Item;\n" +
349+
" rdfs:label \"suffragist\"@en, \"sufrageto\"@eo, \"суфражистка\"@ru, \"suffragetti\"@fi, \"szüfrazsett\"@hu.\n"
350+
+
351+
"\n" +
352+
353+
"wd:other9 wdt:P106 wd:Q27532439 .\n" +
354+
355+
"wd:Q27532438 a wikibase:Item;\n" +
356+
" rdfs:label \"suffragist\"@en, \"sufrageto\"@eo, \"суфражистка\"@ru, \"suffragetti\"@fi, \"szüfrazsett\"@no-nb.\n"
357+
+
358+
359+
"wd:Q89166696 wdt:P106 wd:Q27532437 .\n";
360+
361+
con.add(new StringReader(data), "", RDFFormat.TURTLE);
362+
363+
TupleQuery tupleQuery = con.prepareTupleQuery("PREFIX wdt: <http://www.wikidata.org/prop/direct/>\n" +
364+
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
365+
"SELECT ?occup ?occupLabel ?count\n" +
366+
"WHERE\n" +
367+
"{\n" +
368+
" {\n" +
369+
" SELECT ?occup (COUNT(?person) as ?count)\n" +
370+
" WHERE\n" +
371+
" {\n" +
372+
" ?person wdt:P106 ?occup\n" +
373+
" }\n" +
374+
" GROUP BY ?occup\n" +
375+
" ORDER BY DESC(?count)\n" +
376+
" LIMIT 1000\n" +
377+
" }\n" +
378+
"BIND(\"lv\" AS ?lang)\n" +
379+
" OPTIONAL {" +
380+
" ?occup rdfs:label ?label1. \n" +
381+
" filter(lang(?label1) = ?lang)\n" +
382+
"}\n" +
383+
" FILTER(!BOUND(?label1))\n" +
384+
"?occup rdfs:label ?occupLabel FILTER (LANG(?occupLabel)=\"en\") .\n" +
385+
"\n" +
386+
"}\n" +
387+
"ORDER BY DESC(?count)\n" +
388+
"LIMIT 50");
389+
con.begin();
390+
try (TupleQueryResult evaluate = tupleQuery.evaluate()) {
391+
assertTrue(evaluate.hasNext());
392+
}
393+
con.commit();
394+
395+
}
396+
327397
}

0 commit comments

Comments
 (0)