[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-recutils] New support for group-by and aggregates

From: Jose E. Marchesi
Subject: [bug-recutils] New support for group-by and aggregates
Date: Fri, 25 May 2012 01:06:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Hi people.

The support for aggregates and grouping of fields is now in the trunk in
the git repo.  It is not documented yet, nor well tested, but you can
play with it if you feel like that and want to help debugging it :)

Aggregates can be invoked in any of the -p, -P or -R options, by simply
including a function call in the field expression, such as in:

$ recsel -p Sum(Score) students.rec

Grouping, having similar semantics to the GROUP BY sql construction, is
supported using the -G option.  So we could write something like:

$ recsel -p Name,Avg(Score) -G Name students.rec
Name: Mr. Foo
Avg_Score: 6.2

Name: Mr. Bar
Avg_Score: 2.3

Rewrite rules can be used in the function calls, like in any other entry
of a fex.  For example:

$ recsel -p Name,Avg(Score):GlobalScore -G Name students.rec
Name: Mr. Foo
GlobalScore: 6.2

Name; Mr. Bar
GlobalScore: 2.3

It is possible to call any number of aggregates in the field expression,
and also to group by several fields.  So, we would get the money
resulting from the sales of artiles in each day by using something like:

$ recsel -p Article,Date,Sum(Amount) sales.rec

The supported aggregated functions are count, avg, sum, min and max,
with the obvious semantics... can you think on any other useful
aggregate I must add? :)

Note that the names of the aggregates are case-insensitive, so
count(Score) is like Count(Score).

Now... try to break it and report any problem/bug you find!  Have fun!

PS: Incidentally it is now possible to sort records using several
fields.  Just pass a comma separated list of field names to -G.

Jose E. Marchesi         http://www.jemarch.net
GNU Project              http://www.gnu.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]