001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2003-2005 Julian Hyde
008// Copyright (C) 2005-2012 Pentaho
009// All Rights Reserved.
010*/
011package mondrian.olap;
012
013import mondrian.calc.Calc;
014import mondrian.calc.TupleList;
015import mondrian.spi.Dialect.Datatype;
016import mondrian.spi.SegmentBody;
017
018import java.util.List;
019
020/**
021 * Describes an aggregation operator, such as "sum" or "count".
022 *
023 * @see FunDef
024 * @see Evaluator
025 *
026 * @author jhyde$
027 * @since Jul 9, 2003$
028 */
029public interface Aggregator {
030    /**
031     * Returns the aggregator used to combine sub-totals into a grand-total.
032     *
033     * @return aggregator used to combine sub-totals into a grand-total
034     */
035    Aggregator getRollup();
036
037    /**
038     * Applies this aggregator to an expression over a set of members and
039     * returns the result.
040     *
041     * @param evaluator Evaluation context
042     * @param members List of members, not null
043     * @param calc Expression to evaluate
044     *
045     * @return result of applying this aggregator to a set of members/tuples
046     */
047    Object aggregate(Evaluator evaluator, TupleList members, Calc calc);
048
049    /**
050     * Tells Mondrian if this aggregator can perform fast aggregation
051     * using only the raw data of a given object type. This will
052     * determine if Mondrian will attempt to perform in-memory rollups
053     * on raw segment data by invoking {@link #aggregate}.
054     *
055     * <p>This is only invoked for rollup operations.
056     *
057     * @param datatype The datatype of the object we would like to rollup.
058     * @return Whether this aggregator supports fast aggregation
059     */
060    boolean supportsFastAggregates(Datatype datatype);
061
062    /**
063     * Applies this aggregator over a raw list of objects for a rollup
064     * operation. This is useful when the values are already resolved
065     * and we are dealing with a raw {@link SegmentBody} object.
066     *
067     * <p>Only gets called if
068     * {@link #supportsFastAggregates(mondrian.spi.Dialect.Datatype)} is true.
069     *
070     * <p>This is only invoked for rollup operations.
071     *
072     * @param rawData An array of values in its raw form, to be aggregated.
073     * @return A rolled up value of the raw data.
074     * if the object type is not supported.
075     */
076    Object aggregate(List<Object> rawData, Datatype datatype);
077}
078
079// End Aggregator.java