Re: Aggregate Support to the ORM

2008-05-03 Thread Russell Keith-Magee
On Thu, May 1, 2008 at 10:07 PM, Nicolas E. Lara G. <[EMAIL PROTECTED]> wrote: > > Hello, > > With (1) we can get unexpected results. Imagine we were not using max > but sum instead, the buyer's age would be sumed as many times as he > has made a purchase. I disagree that (1) is unexpected -

RE: Aggregate Support to the ORM

2008-05-02 Thread David Cramer
Also I believe group by shouldn't happen on every column unless explicit. By default it should group on primary key. -Original Message- From: Yuri Baburov <[EMAIL PROTECTED]> Sent: Thursday, May 01, 2008 1:53 PM To: django-developers@googlegroups.com Subject: Re: Aggregate

RE: Aggregate Support to the ORM

2008-05-02 Thread David Cramer
colas Lara <[EMAIL PROTECTED]> Sent: Friday, May 02, 2008 10:12 AM To: django-developers@googlegroups.com Subject: Re: Aggregate Support to the ORM I am not sure I agree with you on this. Since the succesive calls to aggregate/annotate would actually be constructing the elements for the fi

Re: Aggregate Support to the ORM

2008-05-02 Thread Nicolas Lara
I am not sure I agree with you on this. Since the succesive calls to aggregate/annotate would actually be constructing the elements for the final query in non ordered datastructures I think the order in which different elements are inserted to the aggregation should not matter. The values modifier

Re: Aggregate Support to the ORM

2008-05-02 Thread Nicolas Lara
> It's probably > not a good idea to assume either point of view. I agree > I wonder if aggregate functions on the quesyset's model should even be > allowed in annotate(). I can't think of a case that makes sense. That > restriction would certainly get rid of some ambiguity. This is a solution

Re: Aggregate Support to the ORM

2008-05-01 Thread Yuri Baburov
can this be considered as difference of complex apply against 2 consequent applications of annotate? like 2 filter applied one-by-one can be different from one complex filter? like: .annotate('purchases__quantity__sum').annotate('age__max') and .annotate('purchases__quantity__sum', 'age__max')? co

Re: Aggregate Support to the ORM

2008-05-01 Thread Justin Fagnani
Interesting problem. The real question is, what is the user's intent on a query like that? I have no idea. They probably are thinking along the lines of result #2 if they don't understand the underlying SQL and #1 if they do. It's probably not a good idea to assume either point of view. Using Sum

Re: Aggregate Support to the ORM

2008-05-01 Thread Nicolas E. Lara G.
Hello, I've been looking into the different use cases for aggregation and came across one that I wasn't very sure what should be the expected behaviour (regardless of the syntax used to express it) If we do something like: Buyer.objects.all().annotate('purchases__quantity__sum', 'age__max') or

Re: Aggregate Support to the ORM

2008-04-29 Thread Nicolas Lara
On Tue, Apr 29, 2008 at 12:49 PM, David Cramer <[EMAIL PROTECTED]> wrote: > > Is it my understanding that aggregate would not return an actual > object (from the original examples above). > > Also, in regards to HAVING support. Unless you plan to implement logic > into .filter() which says "oh

Re: Aggregate Support to the ORM

2008-04-29 Thread David Cramer
Is it my understanding that aggregate would not return an actual object (from the original examples above). Also, in regards to HAVING support. Unless you plan to implement logic into .filter() which says "oh hey this is from an aggregate, using having" then this is a MUST. There's no other way y

Re: Aggregate Support to the ORM

2008-04-29 Thread Nicolas Lara
On Tue, Apr 29, 2008 at 1:25 AM, Justin Fagnani <[EMAIL PROTECTED]> wrote: > > > On Mon, Apr 28, 2008 at 2:10 PM, Nicolas E. Lara G. <[EMAIL PROTECTED]> > wrote: > > I didn't understand your point here. When is the data incomplete? > > An example would be grouping people by age and averaging incom

Re: Aggregate Support to the ORM

2008-04-28 Thread Justin Fagnani
On Mon, Apr 28, 2008 at 2:10 PM, Nicolas E. Lara G. <[EMAIL PROTECTED]> wrote: > I didn't understand your point here. When is the data incomplete? An example would be grouping people by age and averaging income, what should the values of the name field be? None might make sense at first, as Honz

Re: Aggregate Support to the ORM

2008-04-28 Thread Nicolas E. Lara G.
Hi Justin, > I really like Honza's idea of an AggregateModel, at least for cases where > there's a 1-1 correspondence between results and actual instances, so that > the model will still behave as expected. To keep from cluttering the model's > attributes, aggregate values could be put into anoth

Re: Aggregate Support to the ORM

2008-04-28 Thread Justin Fagnani
Hey everyone, Good to see this has come up again. Congrats on getting the GSoC selection Nicolas. The previous thread[1] has a lot of good discussion in it if anyone here wasn't following that. Obviously, I prefer the expression object API. I've actually been using it a bit in an order processing

Re: Aggregate Support to the ORM

2008-04-27 Thread Nicolas Lara
> That was my thinking exactly. I think the cognitive dissonance > involved in height__avg='average_height' is much greater than that in > ({'average_height': 'height__avg}). Sure, it's new ORM syntax but it's > also a new ORM feature. Overloading the existing syntax to do > something that's

Re: Aggregate Support to the ORM

2008-04-27 Thread Simon Willison
On Apr 27, 1:59 am, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > Its mostly there as a convenience for the really simple cases. There > some duplication in typing annotate(avg_height=Avg('height'), so the > shortcut is a convenience. IMHO, this is the sort of thing could be > easily explaine

Re: Aggregate Support to the ORM

2008-04-26 Thread [EMAIL PROTECTED]
I like the lookup objects idea for aggregates, it's similar to Q objects and I think it works well. It is far more extensible then the __ notation. On Apr 26, 7:59 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > On Sun, Apr 27, 2008 at 6:32 AM, Simon Willison <[EMAIL PROTECTED]> wrote: >

Re: Aggregate Support to the ORM

2008-04-26 Thread Russell Keith-Magee
On Sun, Apr 27, 2008 at 6:32 AM, Simon Willison <[EMAIL PROTECTED]> wrote: > > On Apr 26, 12:33 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> > wrote: > > > If the aggregate function is provided as an anonymous argument (e.g., > > Avg('height')), then the aggregate is asked to provide an appro

Re: Aggregate Support to the ORM

2008-04-26 Thread Simon Willison
On Apr 26, 12:33 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > So - here's a slightly modified proposal. Last time this topic came up > on django-dev, Justin Fagnani made an interesting suggestion which I > think will answer your objections, and leaves open some interesting > possibiliti

Re: Aggregate Support to the ORM

2008-04-26 Thread Russell Keith-Magee
On Sat, Apr 26, 2008 at 6:32 PM, Simon Willison <[EMAIL PROTECTED]> wrote: > > On Apr 26, 7:34 am, "Ian Kelly" <[EMAIL PROTECTED]> wrote: > > On Fri, Apr 25, 2008 at 11:40 PM, Russell Keith-Magee > > > > > <[EMAIL PROTECTED]> wrote: > > > > Have you considered syntax that looks like this ins

Re: Aggregate Support to the ORM

2008-04-26 Thread Simon Willison
On Apr 26, 7:34 am, "Ian Kelly" <[EMAIL PROTECTED]> wrote: > On Fri, Apr 25, 2008 at 11:40 PM, Russell Keith-Magee > > <[EMAIL PROTECTED]> wrote: > > > Have you considered syntax that looks like this instead? : > > > >>> Students.objects.all().aggregate({'average_height': 'height__avg}) > > >

Re: Aggregate Support to the ORM

2008-04-25 Thread Ian Kelly
On Fri, Apr 25, 2008 at 11:40 PM, Russell Keith-Magee <[EMAIL PROTECTED]> wrote: > > Have you considered syntax that looks like this instead? : > > >>> Students.objects.all().aggregate({'average_height': 'height__avg}) > > > {'average_height' : 1.43} > > My issue with this syntax is that ev

Re: Aggregate Support to the ORM

2008-04-25 Thread Russell Keith-Magee
On Fri, Apr 25, 2008 at 9:35 PM, Simon Willison <[EMAIL PROTECTED]> wrote: > > On Apr 22, 9:24 pm, "Nicolas E. Lara G." <[EMAIL PROTECTED]> > wrote: > > > So a QuerySet might be: > > >>> Students.objects.all().aggregate(height__avg='average_height') > > {'average_height' : 1.43} > > This look

Re: Aggregate Support to the ORM

2008-04-25 Thread Simon Willison
On Apr 22, 9:24 pm, "Nicolas E. Lara G." <[EMAIL PROTECTED]> wrote: > So a QuerySet might be: > >>> Students.objects.all().aggregate(height__avg='average_height') > {'average_height' : 1.43} This looks really great, but one thing that initially confused me was the ordering of the arguments - it s

Re: Aggregate Support to the ORM

2008-04-22 Thread Nicolas E. Lara G.
On Apr 22, 4:37 pm, "Rajeev J Sebastian" <[EMAIL PROTECTED]> wrote: > Hi Nicolas, > > First, congratulations on your GSOC selection :) > Thanks =) > I would to know if you will be building some way to use PG custom > aggregates. I have so far one custom aggregate and I wonder how it > could wor

Re: Aggregate Support to the ORM

2008-04-22 Thread Nicolas E. Lara G.
On Apr 22, 4:36 pm, Matthias Kestenholz <[EMAIL PROTECTED]> wrote: > Hi. > > this is very exciting! I've one suggestion/question though. > > On Tue, 2008-04-22 at 13:24 -0700, Nicolas E. Lara G. wrote: > > > with the possibility of using non-keyword arguments for un-aliased > > aggregation, in w

Re: Aggregate Support to the ORM

2008-04-22 Thread [EMAIL PROTECTED]
Looks like good stuff, the one thing that would be nice would be to have annotate return Model Objects instead of dicts. On Apr 22, 3:37 pm, "Rajeev J Sebastian" <[EMAIL PROTECTED]> wrote: > Hi Nicolas, > > First, congratulations on your GSOC selection :) > > I would to know if you will be buildi