[storm] error on ResultSet.count( ) after group_by( )
James Henstridge
james at jamesh.id.au
Thu Jan 22 12:34:29 GMT 2009
On Thu, Jan 22, 2009 at 10:48 PM, Eduardo Willians <edujurista at gmail.com> wrote:
>>>> result = broker.find(Ctb, Ctb.expiration < base,
> Ctb.spc == False).order_by(Ctb.expiration)
>>>> result.group_by(Ctb.op_id)
> <storm.store.ResultSet object at 0x01A5E290>
>>>> result.count()
> Traceback (most recent call last):
> File "<pyshell#4>", line 1, in <module>
> result.count()
> File "d:\SisTemporal 9.01\narnia\geosql\storm\store.py", line 1216, in count
> return int(self._aggregate(Count(expr, distinct)))
> File "d:\SisTemporal 9.01\narnia\geosql\storm\store.py", line 1189,
> in _aggregate
> raise FeatureError("Single aggregates aren't supported after a "
> FeatureError: Single aggregates aren't supported after a GROUP BY clause
>>>>
>
> Why this?
So, when you do store.find(Ctb, ...), you are selecting all columns
from that table including the primary key.
You later try to group on one column (Ctb.op_id) which I assume is not
the primary key. If you have two rows with the same value for op_id
but different primary keys, then it is ambiguous as to what should be
returned.
If you only want to select certain columns from the table, you could
do so with e.g.:
result = store.find(Ctb.op_id, ...)
result.group_by(Ctb.op_id)
The results here will just be the column value rather than Ctb
objects. Alternatively, if you are selecting from multiple tables,
you can select one table class plus a number of aggregates from the
other table pretty easily.
James.
More information about the storm
mailing list