I've done some more work on this little project and have managed to
produce a significantly more idiomatic version. Since it has turned into
a full blown patch series, I'll save your inboxes and direct you
to the whole queue at

  http://raidi.us/edarc/sqlalchemy

This contains the iterator result-concatenation patch and the
_merge_ordering() patch I already posted. The new material is
ShardedQuery._merge_by(), which behaves a lot like order_by() does:

>>> q = sess.query(Person).order_by(Person.age)
>>> mq = q._merge_by(Person.age)

There are two versions of its implementation, one based on the other.

The original one tries to find mapper properties on the instances or
column entities that match the expressions given. The upside is that it
doesn't alter the generated SQL. The downside is that it's kind of
fragile and can silently break in wierd ways, such as if the mapped
class sets up it's own property accessors that mutate the value in a way
that might change the comparison behavior and resultant ordering. It
also gives up and raises an exception if it can't find said properties
or columns (for reasons which may or may not constitute a user error).

The second version eschews this magic for a more robust method, which
involves adding column entities to the query that are used find the
merge ordering and are then stripped from the results before the query
returns them. Upside is that AFAIK it works with any expression that can
be order_by()'ed, downside is obviously that it changes the generated
SQL. It does, however, check to see if the user already explicitly added
a matching column entity to the query, and uses that instead of
duplicating it.

I didn't add tests for _merge_by() in these patches, but I do have some
standalone tests that I've run on them. I'll probably add some tests
into the SA suite for it in the next day or two.

There are some rough edges, particularly reduce_ordering_expression(),
that I'm fairly sure are not done The Right Way, and there are probably
some latent bugs, so I'd be interested in any feedback.

Enjoy,
Kyle

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to