/* // $Id: //guest/julian_hyde/saffron/src/main/saffron/rel/Aggregation.java#1 $ // Saffron preprocessor and data engine // Copyright (C) 2002 Julian Hyde <julian.hyde@mail.com> // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public // License along with this library; if not, write to the // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // See the COPYING file located in the top-level-directory of // the archive of this library for complete text of license. */ package saffron.rel; import openjava.mop.OJClass; import openjava.ptree.Expression; import saffron.opt.Implementor; /** * An <code>Aggregation</code> aggregates a set of values into one value. * * <p> It is used, via a {@link Aggregate.Call}, in an {@link Aggregate} * relational operator. * * <p> To help you understand the terminology, here are some analogies: an * {@link Aggregation} is analogous to a {@link openjava.mop.OJMethod}, whereas * a {@link #Call} is analogous to a {@link openjava.ptree.MethodCall}. {@link * AggregatorExtender} has no direct analog in Java: it is more like a function * object in JScript. * * <p> For user-defined aggregates, use you should generally use {@link * AggregatorExtender}; writing a new <code>Aggregation</code> is a complicated * task, akin to writing a new relational operator ({@link saffron.rel.Rel}). * * @see AggregatorExtender * * @author jhyde * @since 26 January, 2001 * @version $Id: //guest/julian_hyde/saffron/src/main/saffron/rel/Aggregation.java#1 $ **/ public interface Aggregation { OJClass getReturnType(); OJClass[] getParameterTypes(); /** * Whether this aggregator can merge together two * accumulators. <code>count</code> can (you just add the accumulators); * <code>avg</code> and {@link saffron.runtime.Nth} cannot. **/ boolean canMerge(); /** * Generates the expression which gets called when a new total is * created. For <code>sum(x)</code>, this looks like <code>new * saffron.runtime.Holder.int_Holder(0)</code>. **/ Expression implementStart(Implementor implementor, Rel rel, int[] args); /** * Generates (into the current statement list, gleaned by calling * <code>implementor</code>'s {@link Implementor#getStatementList} method) * the piece of code which gets called each time an extra row is seen. For * <code>sum(x)</code>, this looks like * <code>((saffron.runtime.Holder.int_Holder) accumulator).value += x</code>. * * @param implementor a callback object which knows how to generate things * @param rel the relational expression which is generating this code * @param accumulator the expression which holds the total * @param args the ordinals of the fields of the child row which are * arguments to this aggregator **/ void implementNext( Implementor implementor, Rel rel, Expression accumulator, int[] args); /** * Generates (into the current statement list, gleaned by calling * <code>implementor</code>'s {@link Implementor#getStatementList} method) * code to merge two accumulators. For <code>sum(x)</code>, this looks like * <code>((saffron.runtime.Holder.int_Holder) accumulator).value += * ((saffron.runtime.Holder.int_Holder) other).value</code>. * * <p> The method is only called if {@link #canMerge} returns * <code>true</code>. * * @param implementor a callback object which knows how to generate things * @param rel the relational expression which is generating this code * @param accumulator the expression which holds the total * @param otherAccumulator accumulator to merge in **/ void implementMerge( Implementor implementor, Rel rel, Expression accumulator, Expression otherAccumulator); /** * Generates the expression which gets called when a total is complete. For * <code>sum(x)</code>, this looks like <code> * ((saffron.runtime.Holder.int_Holder) accumulator).value</code>. **/ Expression implementResult(Expression accumulator); } // End Aggregation.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 1474 | Julian Hyde |
saffron: Aggregations are working. Renamed 'aggregator' to 'aggregation'. |
||
#1 | 1467 | Julian Hyde |
saffron: First saffron check-in; incorporate my changes to openjava. |