Skip to content

Commit fa4dde0

Browse files
committed
fixed nested union mysql error
1 parent daedc1a commit fa4dde0

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

LNX-docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ services:
3232
interval: 1s
3333
fakeservices.datajoint.io:
3434
<<: *net
35-
image: datajoint/nginx:v0.0.18
35+
image: datajoint/nginx:v0.0.19
3636
environment:
3737
- ADD_db_TYPE=DATABASE
3838
- ADD_db_ENDPOINT=db:3306

datajoint/expression.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def from_clause(self):
9898
return clause
9999

100100
def where_clause(self):
101-
return '' if not self.restriction else ' WHERE(%s)' % ')AND('.join(
101+
return '' if not self.restriction else ' WHERE (%s)' % ')AND('.join(
102102
str(s) for s in self.restriction)
103103

104104
def make_sql(self, fields=None):
@@ -620,15 +620,17 @@ def create(cls, arg1, arg2):
620620
result._support = [arg1, arg2]
621621
return result
622622

623+
__count = count()
624+
623625
def make_sql(self):
624626
arg1, arg2 = self._support
625627
if not arg1.heading.secondary_attributes and not arg2.heading.secondary_attributes:
626628
# no secondary attributes: use UNION DISTINCT
627629
fields = arg1.primary_key
628-
return "({sql1}) UNION ({sql2})".format(
630+
return ("SELECT * FROM (({sql1}) UNION ({sql2})) as `_u%x`".format(
629631
sql1=arg1.make_sql() if isinstance(arg1, Union) else arg1.make_sql(fields),
630632
sql2=arg2.make_sql() if isinstance(arg2, Union) else arg2.make_sql(fields),
631-
)
633+
)) % next(self.__count)
632634
# with secondary attributes, use union of left join with antijoin
633635
fields = self.heading.names
634636
sql1 = arg1.join(arg2, left=True).make_sql(fields)

local-docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ services:
3434
interval: 1s
3535
fakeservices.datajoint.io:
3636
<<: *net
37-
image: datajoint/nginx:v0.0.18
37+
image: datajoint/nginx:v0.0.19
3838
environment:
3939
- ADD_db_TYPE=DATABASE
4040
- ADD_db_ENDPOINT=db:3306

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
__author__ = 'Edgar Walker, Fabian Sinz, Dimitri Yatsenko, Raphael Guzman'
2121

2222
# turn on verbose logging
23-
#logging.basicConfig(level=logging.DEBUG)
23+
logging.basicConfig(level=logging.DEBUG)
2424

2525
__all__ = ['__author__', 'PREFIX', 'CONN_INFO']
2626

tests/test_relational_operand.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,5 +513,5 @@ def test_union_multiple():
513513
q2 = (IJ & dict(j=2, i=0)) + (IJ & dict(j=2, i=1)) + (IJ & dict(j=2, i=2))
514514
x = set(zip(*q1.fetch('i', 'j')))
515515
y = set(zip(*q2.fetch('i', 'j')))
516-
assert_set_equal(x, y)
517-
assert q1.fetch() == q2.fetch()
516+
assert x == y
517+
assert any(q1.fetch() == q2.fetch())

0 commit comments

Comments
 (0)