diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-19 00:32:00 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-19 00:34:20 -0400 |
| commit | 699da7ecb96e9e1af8df8072d53199a560311260 (patch) | |
| tree | d59316fa85f5fce8b6fc25776602de05e6a75f5f /test | |
| parent | 5624430eb1d07c68d0931bc89f7146bc003fde19 (diff) | |
| download | sqlalchemy-699da7ecb96e9e1af8df8072d53199a560311260.tar.gz | |
perf tweaks
- avoid abc checks in distill_20
- ColumnEntity subclasses are unique to their compile state and
have no querycontext specific state. They can do a simple memoize of their
fetch_column without using attributes, and they can memoize their
_getter() too so that it goes into the cache, just like
instance_processor() does.
- unify ORMColumnEntity and RawColumnEntity for the row processor part,
add some test coverage for the case where it is used in a from_statement
- do a faster generate if there are no memoized entries
- query._params is always immutabledict
Change-Id: I1e2dfe607a1749b5b434fc11f9348ee631501dfa
Diffstat (limited to 'test')
| -rw-r--r-- | test/orm/test_froms.py | 12 | ||||
| -rw-r--r-- | test/orm/test_lazy_relations.py | 4 | ||||
| -rw-r--r-- | test/orm/test_query.py | 35 |
3 files changed, 48 insertions, 3 deletions
diff --git a/test/orm/test_froms.py b/test/orm/test_froms.py index 1fde343d8..62227ece2 100644 --- a/test/orm/test_froms.py +++ b/test/orm/test_froms.py @@ -2310,6 +2310,18 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): ) assert result == expected + def test_multi_columns_3(self): + User = self.classes.User + users = self.tables.users + + sess = create_session() + + q = sess.query(User.id, User.name) + stmt = select([users]).order_by(users.c.id) + q = q.from_statement(stmt) + + eq_(q.all(), [(7, "jack"), (8, "ed"), (9, "fred"), (10, "chuck")]) + def test_raw_columns(self): addresses, users, User = ( self.tables.addresses, diff --git a/test/orm/test_lazy_relations.py b/test/orm/test_lazy_relations.py index 65158dbd4..c30086bea 100644 --- a/test/orm/test_lazy_relations.py +++ b/test/orm/test_lazy_relations.py @@ -439,9 +439,7 @@ class LazyTest(_fixtures.FixtureTest): def process_query_conditionally(self, query): """process query during a lazyload""" canary() - params = dict(query.load_options._params) - query.load_options += {"_params": params} - query.load_options._params.update(dict(name=self.crit)) + query.params.non_generative(query, dict(name=self.crit)) s = Session() ed = s.query(User).options(MyOption("ed")).filter_by(name="ed").one() diff --git a/test/orm/test_query.py b/test/orm/test_query.py index a7cc82ddf..c2f0c4424 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -4440,6 +4440,26 @@ class TextTest(QueryTest, AssertsCompiledSQL): self.assert_sql_count(testing.db, go, 1) + def test_textual_select_orm_columns(self): + # test that columns using column._label match, as well as that + # ordering doesn't matter. + User = self.classes.User + Address = self.classes.Address + users = self.tables.users + addresses = self.tables.addresses + + s = create_session() + q = s.query(User.name, User.id, Address.id).from_statement( + text( + "select users.name AS users_name, users.id AS users_id, " + "addresses.id AS addresses_id FROM users JOIN addresses " + "ON users.id = addresses.user_id WHERE users.id=8 " + "ORDER BY addresses.id" + ).columns(users.c.name, users.c.id, addresses.c.id) + ) + + eq_(q.all(), [("ed", 8, 2), ("ed", 8, 3), ("ed", 8, 4)]) + @testing.combinations( ( False, @@ -4564,6 +4584,21 @@ class TextTest(QueryTest, AssertsCompiledSQL): [User(id=7), User(id=8), User(id=9), User(id=10)], ) + def test_columns_via_textasfrom_from_statement(self): + User = self.classes.User + s = create_session() + + eq_( + s.query(User.id, User.name) + .from_statement( + text("select * from users order by id").columns( + id=Integer, name=String + ) + ) + .all(), + [(7, "jack"), (8, "ed"), (9, "fred"), (10, "chuck")], + ) + def test_via_textasfrom_use_mapped_columns(self): User = self.classes.User s = create_session() |
