summaryrefslogtreecommitdiff
path: root/test/sql/test_selectable.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-06-25 17:32:51 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-06-26 13:19:45 -0400
commitf76cae4bc92da640c155337da5d089075ebae0d8 (patch)
tree1cf57ae3260dad2639f0dc701ebc8b830cdbf9fe /test/sql/test_selectable.py
parent11447041804dd39d05684c7809971a253c800cba (diff)
downloadsqlalchemy-f76cae4bc92da640c155337da5d089075ebae0d8.tar.gz
- rework of correlation, continuing on #2668, #2746
- add support for correlations to propagate all the way in; because correlations require context now, need to make sure a select enclosure of any level takes effect any number of levels deep. - fix what we said correlate_except() was supposed to do when we first released #2668 - "the FROM clause is left intact if the correlated SELECT is not used in the context of an enclosing SELECT..." - it was not considering the "existing_froms" collection at all, and prohibited additional FROMs from being placed in an any() or has(). - add test for multilevel any() - lots of docs, including glossary entries as we really need to define "WHERE clause", "columns clause" etc. so that we can explain correlation better - based on the insight that a SELECT can correlate anything that ultimately came from an enclosing SELECT that links to this one via WHERE/columns/HAVING/ORDER BY, have the compiler keep track of the FROM lists that correspond in this way, link it to the asfrom flag, so that we send to _get_display_froms() the exact list of candidate FROMs to correlate. no longer need any asfrom logic in the Select() itself - preserve 0.8.1's behavior for correlation when no correlate options are given, not to mention 0.7 and prior's behavior of not propagating implicit correlation more than one level.. this is to reduce surprises/hard-to-debug situations when a user isn't trying to correlate anything.
Diffstat (limited to 'test/sql/test_selectable.py')
-rw-r--r--test/sql/test_selectable.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py
index 6a0511faa..335083ce1 100644
--- a/test/sql/test_selectable.py
+++ b/test/sql/test_selectable.py
@@ -6,7 +6,7 @@ from sqlalchemy import *
from sqlalchemy.testing import fixtures, AssertsCompiledSQL, \
AssertsExecutionResults
from sqlalchemy import testing
-from sqlalchemy.sql import util as sql_util, visitors
+from sqlalchemy.sql import util as sql_util, visitors, expression
from sqlalchemy import exc
from sqlalchemy.sql import table, column, null
from sqlalchemy import util
@@ -148,6 +148,48 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled
s = select([t])._clone()
assert c in s.c.bar.proxy_set
+ def test_cloned_intersection(self):
+ t1 = table('t1', column('x'))
+ t2 = table('t2', column('x'))
+
+ s1 = t1.select()
+ s2 = t2.select()
+ s3 = t1.select()
+
+ s1c1 = s1._clone()
+ s1c2 = s1._clone()
+ s2c1 = s2._clone()
+ s3c1 = s3._clone()
+
+ eq_(
+ expression._cloned_intersection(
+ [s1c1, s3c1], [s2c1, s1c2]
+ ),
+ set([s1c1])
+ )
+
+ def test_cloned_difference(self):
+ t1 = table('t1', column('x'))
+ t2 = table('t2', column('x'))
+
+ s1 = t1.select()
+ s2 = t2.select()
+ s3 = t1.select()
+
+ s1c1 = s1._clone()
+ s1c2 = s1._clone()
+ s2c1 = s2._clone()
+ s2c2 = s2._clone()
+ s3c1 = s3._clone()
+
+ eq_(
+ expression._cloned_difference(
+ [s1c1, s2c1, s3c1], [s2c1, s1c2]
+ ),
+ set([s3c1])
+ )
+
+
def test_distance_on_aliases(self):
a1 = table1.alias('a1')
for s in (select([a1, table1], use_labels=True),