Merge lp:~therve/storm/217644-count-distinct into lp:storm

Proposed by Thomas Herve
Status: Merged
Merge reported by: Thomas Herve
Merged at revision: not available
Proposed branch: lp:~therve/storm/217644-count-distinct
Merge into: lp:storm
To merge this branch: bzr merge lp:~therve/storm/217644-count-distinct
Reviewer Review Type Date Requested Status
Jamu Kakar (community) Approve
Sidnei da Silva (community) Approve
Review via email: mp+1834@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Thomas Herve (therve) wrote :

This is ready to review. I only handled the COUNT case, as the cases for SUM and AVG seems dubious and not really clean to handle.

284. By Thomas Herve

Handle limit config in count.

285. By Thomas Herve

Handle offset in count, and check that it now works for sliced resultsets.

Revision history for this message
Sidnei da Silva (sidnei) wrote :

Looks great. +1

review: Approve
286. By Thomas Herve

Add some tests in the sqlobject layer.

Revision history for this message
Jamu Kakar (jkakar) wrote :

[1]

     def count(self, expr=Undef, distinct=False):
         """Get the number of objects represented by this ResultSet."""
- return int(self._aggregate(Count(expr, distinct)))
+ if expr is Undef and (self._distinct or self._limit is not Undef or
+ self._offset is not Undef):
+ subselect = self._get_select()
+ select = Select(Count(), tables=Alias(subselect, "_tmp"))
+ result = self._store._connection.execute(select)
+ return int(result.get_one()[0])
+ else:
+ return int(self._aggregate(Count(expr, distinct)))

The behaviour when expr is Undef looks good. ResultSet._distinct is
ignored when it is provided, though. This test fails:

    def test_find_count_column_with_implicit_distinct(self):
        result = self.store.find(Link)
        result.config(distinct=True)
        count = result.count(Link.foo_id)
        self.assertEquals(count, 3)

+1 with this test included and passing.

review: Approve
287. By Thomas Herve

Manage count with expr case, fix a parameter name in EmptyResultSet

Subscribers

People subscribed via source and target branches

to status/vote changes: