Skip to content

Commit 037ea51

Browse files
author
Nicholas Car
authored
Merge pull request #1057 from kushagr08/issue-910
fix #910: Updated evaluate.py so that union includes results of both branches, even when identical.
2 parents 9c064ac + 55c0da3 commit 037ea51

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

rdflib/plugins/sparql/evaluate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ def evalJoin(ctx, join):
127127

128128

129129
def evalUnion(ctx, union):
130+
branch1_branch2 = []
130131
for x in evalPart(ctx, union.p1):
131-
yield x
132+
branch1_branch2.append(x)
132133
for x in evalPart(ctx, union.p2):
133-
yield x
134+
branch1_branch2.append(x)
135+
return branch1_branch2
134136

135137

136138
def evalMinus(ctx, minus):

test/test_issue910.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from rdflib import Graph
2+
import unittest
3+
4+
5+
class TestIssue910(unittest.TestCase):
6+
def testA(self):
7+
g = Graph()
8+
q = g.query(
9+
"""
10+
SELECT * {
11+
{ BIND ("a" AS ?a) }
12+
UNION
13+
{ BIND ("a" AS ?a) }
14+
}
15+
"""
16+
)
17+
self.assertEqual(len(q) == 2, True)
18+
19+
def testB(self):
20+
g = Graph()
21+
q = g.query(
22+
"""
23+
SELECT * {
24+
{ BIND ("a" AS ?a) }
25+
UNION
26+
{ VALUES ?a { "a" } }
27+
UNION
28+
{ SELECT ("a" AS ?a) {} }
29+
}
30+
"""
31+
)
32+
self.assertEqual(len(q) == 3, True)
33+
34+
def testC(self):
35+
g = Graph()
36+
q = g.query(
37+
"""
38+
SELECT * {
39+
{ BIND ("a" AS ?a) }
40+
UNION
41+
{ VALUES ?a { "a" } }
42+
UNION
43+
{ SELECT ("b" AS ?a) {} }
44+
}
45+
"""
46+
)
47+
self.assertEqual(len(q) == 3, True)
48+
49+
def testD(self):
50+
g = Graph()
51+
q = g.query(
52+
"""SELECT * {
53+
{ BIND ("a" AS ?a) }
54+
UNION
55+
{ VALUES ?a { "b" } }
56+
UNION
57+
{ SELECT ("c" AS ?a) {} }
58+
}
59+
"""
60+
)
61+
self.assertEqual(len(q) == 3, True)
62+
63+
64+
if __name__ == "__main__":
65+
unittest.main()

0 commit comments

Comments
 (0)