Summarize
Aggregate and compute
Signature
summarize(operand: Relation, by: AttrList, aggs: Summarization) -> Relation
Examples
summarize(shipments, [:sid], total: sum(:qty))
summarize(shipments, [:sid], total: sum{|t| t.qty * 2 })
summarize(shipments, [:pid, :qty], {total: sum{|t| t.qty * 2 }}, allbut: true)
Description
Computes the relation obtained by taking the projection of operand
on by attributes then extending each tuple t with the result of
aggregations defined by aggs on the tuples from operand matching t.
In SQL terms, SELECT [by], [agg] FROM operand GROUP BY [by].
Implementation notes
As of current Alf version, this operator cannot be translated to SQL code. That means that all computations are done in ruby, which may seriously hurt performance.
Similarly, as summarize tends to be a showstopper during compilation, it
is strongly recommended to use it as high as possible in query expressions
trees so as to delegate the largest possible query parts to data engines.