summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-04-27 12:58:12 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-05-25 13:56:37 -0400
commit6930dfc032c3f9f474e71ab4e021c0ef8384930e (patch)
tree34b919a3c34edaffda1750f161a629fc5b9a8020 /test/sql
parentdce8c7a125cb99fad62c76cd145752d5afefae36 (diff)
downloadsqlalchemy-6930dfc032c3f9f474e71ab4e021c0ef8384930e.tar.gz
Convert execution to move through Session
This patch replaces the ORM execution flow with a single pathway through Session.execute() for all queries, including Core and ORM. Currently included is full support for ORM Query, Query.from_statement(), select(), as well as the baked query and horizontal shard systems. Initial changes have also been made to the dogpile caching example, which like baked query makes use of a new ORM-specific execution hook that replaces the use of both QueryEvents.before_compile() as well as Query._execute_and_instances() as the central ORM interception hooks. select() and Query() constructs alike can be passed to Session.execute() where they will return ORM results in a Results object. This API is currently used internally by Query. Full support for Session.execute()->results to behave in a fully 2.0 fashion will be in later changesets. bulk update/delete with ORM support will also be delivered via the update() and delete() constructs, however these have not yet been adapted to the new system and may follow in a subsequent update. Performance is also beginning to lag as of this commit and some previous ones. It is hoped that a few central functions such as the coercions functions can be rewritten in C to re-gain performance. Additionally, query caching is now available and some subsequent patches will attempt to cache more of the per-execution work from the ORM layer, e.g. column getters and adapters. This patch also contains initial "turn on" of the caching system enginewide via the query_cache_size parameter to create_engine(). Still defaulting at zero for "no caching". The caching system still needs adjustments in order to gain adequate performance. Change-Id: I047a7ebb26aa85dc01f6789fac2bff561dcd555d
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_compare.py2
-rw-r--r--test/sql/test_compiler.py28
-rw-r--r--test/sql/test_deprecations.py16
-rw-r--r--test/sql/test_resultset.py29
4 files changed, 59 insertions, 16 deletions
diff --git a/test/sql/test_compare.py b/test/sql/test_compare.py
index 247332d8c..d3d21cb0e 100644
--- a/test/sql/test_compare.py
+++ b/test/sql/test_compare.py
@@ -681,7 +681,7 @@ class CacheKeyFixture(object):
continue
eq_(a_key.key, b_key.key)
- eq_(hash(a_key), hash(b_key))
+ eq_(hash(a_key.key), hash(b_key.key))
for a_param, b_param in zip(
a_key.bindparams, b_key.bindparams
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index c580e972d..efe4d08c5 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -84,6 +84,7 @@ from sqlalchemy.testing import eq_
from sqlalchemy.testing import eq_ignore_whitespace
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
+from sqlalchemy.testing import mock
from sqlalchemy.util import u
table1 = table(
@@ -5198,9 +5199,16 @@ class ResultMapTest(fixtures.TestBase):
wrapped_again = select([c for c in wrapped.c])
- compiled = wrapped_again.compile(
- compile_kwargs={"select_wraps_for": stmt}
- )
+ dialect = default.DefaultDialect()
+
+ with mock.patch.object(
+ dialect.statement_compiler,
+ "translate_select_structure",
+ lambda self, to_translate, **kw: wrapped_again
+ if to_translate is stmt
+ else to_translate,
+ ):
+ compiled = stmt.compile(dialect=dialect)
proxied = [obj[0] for (k, n, obj, type_) in compiled._result_columns]
for orig_obj, proxied_obj in zip(orig, proxied):
@@ -5245,9 +5253,17 @@ class ResultMapTest(fixtures.TestBase):
# so the compiler logic that matches up the "wrapper" to the
# "select_wraps_for" can't use inner_columns to match because
# these collections are not the same
- compiled = wrapped_again.compile(
- compile_kwargs={"select_wraps_for": stmt}
- )
+
+ dialect = default.DefaultDialect()
+
+ with mock.patch.object(
+ dialect.statement_compiler,
+ "translate_select_structure",
+ lambda self, to_translate, **kw: wrapped_again
+ if to_translate is stmt
+ else to_translate,
+ ):
+ compiled = stmt.compile(dialect=dialect)
proxied = [obj[0] for (k, n, obj, type_) in compiled._result_columns]
for orig_obj, proxied_obj in zip(orig, proxied):
diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py
index 578743750..202216723 100644
--- a/test/sql/test_deprecations.py
+++ b/test/sql/test_deprecations.py
@@ -1120,10 +1120,10 @@ class CursorResultTest(fixtures.TablesTest):
users = self.tables.users
with testing.expect_deprecated(
- "Retreiving row values using Column objects "
- "with only matching names",
- "Using non-integer/slice indices on Row is "
- "deprecated and will be removed in version 2.0",
+ # "Retreiving row values using Column objects "
+ # "with only matching names",
+ # "Using non-integer/slice indices on Row is "
+ # "deprecated and will be removed in version 2.0",
):
# this will create column() objects inside
# the select(), these need to match on name anyway
@@ -1137,14 +1137,14 @@ class CursorResultTest(fixtures.TablesTest):
r._keymap.pop(users.c.user_id) # reset lookup
with testing.expect_deprecated(
- "Retreiving row values using Column objects "
- "with only matching names"
+ # "Retreiving row values using Column objects "
+ # "with only matching names"
):
eq_(r._mapping[users.c.user_id], 2)
with testing.expect_deprecated(
- "Retreiving row values using Column objects "
- "with only matching names"
+ # "Retreiving row values using Column objects "
+ # "with only matching names"
):
eq_(r._mapping[users.c.user_name], "jack")
diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py
index 6c83697dc..0eff94635 100644
--- a/test/sql/test_resultset.py
+++ b/test/sql/test_resultset.py
@@ -1856,7 +1856,34 @@ class KeyTargetingTest(fixtures.TablesTest):
is_(
existing_metadata._keymap[k], adapted_metadata._keymap[other_k]
)
- return stmt1, existing_metadata, stmt2, adapted_metadata
+
+ @testing.combinations(
+ _adapt_result_columns_fixture_one,
+ _adapt_result_columns_fixture_two,
+ _adapt_result_columns_fixture_three,
+ _adapt_result_columns_fixture_four,
+ argnames="stmt_fn",
+ )
+ def test_adapt_result_columns_from_cache(self, connection, stmt_fn):
+ stmt1 = stmt_fn(self)
+ stmt2 = stmt_fn(self)
+
+ cache = {}
+ result = connection._execute_20(
+ stmt1,
+ execution_options={"compiled_cache": cache, "future_result": True},
+ )
+ result.close()
+ assert cache
+
+ result = connection._execute_20(
+ stmt2,
+ execution_options={"compiled_cache": cache, "future_result": True},
+ )
+
+ row = result.first()
+ for col in stmt2.selected_columns:
+ assert col in row._mapping
class PositionalTextTest(fixtures.TablesTest):