Skip to content

Commit

Permalink
Merge pull request #1057 from kushagr08/issue-910
Browse files Browse the repository at this point in the history
fix #910: Updated evaluate.py so that union includes results of both branches, even when identical.
  • Loading branch information
nicholascar authored May 25, 2020
2 parents 9c064ac + 55c0da3 commit 037ea51
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rdflib/plugins/sparql/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ def evalJoin(ctx, join):


def evalUnion(ctx, union):
branch1_branch2 = []
for x in evalPart(ctx, union.p1):
yield x
branch1_branch2.append(x)
for x in evalPart(ctx, union.p2):
yield x
branch1_branch2.append(x)
return branch1_branch2


def evalMinus(ctx, minus):
Expand Down
65 changes: 65 additions & 0 deletions test/test_issue910.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from rdflib import Graph
import unittest


class TestIssue910(unittest.TestCase):
def testA(self):
g = Graph()
q = g.query(
"""
SELECT * {
{ BIND ("a" AS ?a) }
UNION
{ BIND ("a" AS ?a) }
}
"""
)
self.assertEqual(len(q) == 2, True)

def testB(self):
g = Graph()
q = g.query(
"""
SELECT * {
{ BIND ("a" AS ?a) }
UNION
{ VALUES ?a { "a" } }
UNION
{ SELECT ("a" AS ?a) {} }
}
"""
)
self.assertEqual(len(q) == 3, True)

def testC(self):
g = Graph()
q = g.query(
"""
SELECT * {
{ BIND ("a" AS ?a) }
UNION
{ VALUES ?a { "a" } }
UNION
{ SELECT ("b" AS ?a) {} }
}
"""
)
self.assertEqual(len(q) == 3, True)

def testD(self):
g = Graph()
q = g.query(
"""SELECT * {
{ BIND ("a" AS ?a) }
UNION
{ VALUES ?a { "b" } }
UNION
{ SELECT ("c" AS ?a) {} }
}
"""
)
self.assertEqual(len(q) == 3, True)


if __name__ == "__main__":
unittest.main()

0 comments on commit 037ea51

Please sign in to comment.