Skip to content

Commit eeca99b

Browse files
committed
Fix #930 union join bug, Add test for union join.
1 parent 7764467 commit eeca99b

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

datajoint/expression.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,11 @@ def join(self, other, semantic_check=True, left=False):
266266
- join_attributes)
267267
# need subquery if any of the join attributes are derived
268268
need_subquery1 = (need_subquery1 or isinstance(self, Aggregation) or
269-
any(n in self.heading.new_attributes for n in join_attributes))
269+
any(n in self.heading.new_attributes for n in join_attributes)
270+
or isinstance(self, Union))
270271
need_subquery2 = (need_subquery2 or isinstance(other, Aggregation) or
271-
any(n in other.heading.new_attributes for n in join_attributes))
272+
any(n in other.heading.new_attributes for n in join_attributes)
273+
or isinstance(self, Union))
272274
if need_subquery1:
273275
self = self.make_subquery()
274276
if need_subquery2:

tests/test_aggr_regressions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ class X(dj.Lookup):
9393
"""
9494
contents = zip(range(10))
9595

96+
@schema
97+
class TableA(dj.Manual):
98+
definition = """
99+
table_a: int
100+
"""
101+
102+
103+
@schema
104+
class TableB(dj.Manual):
105+
definition = """
106+
-> TableA
107+
table_b: int
108+
"""
109+
96110

97111
def test_issue558_part1():
98112
q = (A-B).proj(id2='3')
@@ -103,3 +117,12 @@ def test_issue558_part2():
103117
d = dict(id=3, id2=5)
104118
assert_equal(len(X & d), len((X & d).proj(id2='3')))
105119

120+
121+
def test_union_join():
122+
# https://github.com/datajoint/datajoint-python/issues/930
123+
TableA.insert(zip([1, 2, 3, 4, 5, 6]))
124+
TableB.insert([(1, 11), (2, 22), (3, 33), (4, 44)])
125+
q1 = TableB & 'table_a < 3'
126+
q2 = TableB & 'table_a > 3'
127+
128+
(q1 + q2) * TableA

0 commit comments

Comments
 (0)