KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > sql > execute > ExecAggregator


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.execute.ExecAggregator
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.sql.execute;
23
24 import org.apache.derby.iapi.types.DataValueDescriptor;
25 import org.apache.derby.iapi.error.StandardException;
26 import org.apache.derby.iapi.services.io.Formatable;
27
28 /**
29  * An ExecAggregator is the interface that execution uses
30  * to an aggregate. System defined aggregates will implement
31  * this directly.
32  
33    <P>
34    The life time of an ExecAggregator is as follows.
35
36     <OL>
37     <LI> An ExecAggregator instance is created using the defined class name.
38     <LI> Its setup() method is called to define its role (COUNT(*), SUM, etc.).
39     <LI> Its newAggregator() method may be called any number of times to create
40     new working aggregators as required. These aggregators have the same role
41     and must be created in an initialized state.
42     <LI> accumlate and merge will be called across these set of aggregators
43     <LI> One of these aggregators will be used as the final one for obtaining the result
44     </OL>
45
46
47  * <P>
48  */

49 public interface ExecAggregator extends Formatable
50 {
51     /**
52         Set's up the aggregate for processing.
53      */

54     public void setup(String JavaDoc aggregateName);
55
56     /**
57      * Iteratively accumulates the addend into the aggregator.
58      * Called on each member of the set of values that is being
59      * aggregated.
60      *
61      * @param addend the DataValueDescriptor addend (current input to
62      * the aggregation)
63      * @param ga a result set getter
64      *
65      * @exception StandardException on error
66      */

67     public void accumulate
68     (
69         DataValueDescriptor addend,
70         Object JavaDoc ga
71     ) throws StandardException;
72
73     /**
74      * Merges one aggregator into a another aggregator.
75      * Merges two partial aggregates results into a single result.
76      * Needed for: <UL>
77      * <LI> parallel aggregation </LI>
78      * <LI> vector aggregation (GROUP BY) </LI>
79      * <LI> distinct aggregates (e.g. MAX(DISTINCT Col)) </LI></UL><p>
80      *
81      * An example of a merge would be: given two COUNT()
82      * aggregators, C1 and C2, a merge of C1 into C2 would
83      * set C1.count += C2.count. So, given a <i>CountAggregator</i>
84      * with a <i>getCount()</i> method that returns its counts, its
85      * merge method might look like this: <pre>
86
87         public void merge(ExecAggregator inputAggregator) throws StandardException
88         {
89         &nbsp;&nbsp;&nbsp;count += ((CountAccgregator)inputAggregator).getCount();
90         } </pre>
91      *
92      *
93      * @param inputAggregator the other Aggregator
94      * (input partial aggregate)
95      *
96      * @exception StandardException on error
97      */

98     public void merge(ExecAggregator inputAggregator) throws StandardException;
99
100     /**
101      * Produces the result to be returned by the query.
102      * The last processing of the aggregate.
103      *
104      * @exception StandardException on error
105      */

106     public DataValueDescriptor getResult() throws StandardException;
107
108     /**
109        Return a new initialized copy of this aggregator, any state
110        set by the setup() method of the original Aggregator must be
111        copied into the new aggregator.
112      *
113      * @return ExecAggregator the new aggregator
114      */

115     public ExecAggregator newAggregator();
116     
117     /**
118         Return true if the aggregation eliminated at least one
119         null from the input data set.
120     */

121     public boolean didEliminateNulls();
122 }
123
Popular Tags