01: /*
02:
03: Derby - Class org.apache.derby.impl.sql.compile.AggregateDefinition
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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.impl.sql.compile;
23:
24: import java.lang.StringBuffer;
25: import org.apache.derby.catalog.TypeDescriptor;
26: import java.sql.SQLException;
27:
28: /**
29: * An AggregateDefinition defines an aggregate.
30: *
31: * It is used
32: * by Cloudscape during query compilation to determine what
33: * Aggregator is used to aggregate a particular data type
34: * and what datatype the Aggregator will emit. A single
35: * AggregateDefinition may map to one or more Aggregators
36: * depending on the input type. For example, a user defined
37: * STDEV aggregate may use one aggregator implementation for the
38: * INTEGER type and another for a user defined type that implements
39: * a point. In this case, both the aggregators would have a
40: * single AggregateDefinition that would chose the appropriate
41: * aggregator based on the input type. On the other hand, if
42: * only a single aggregator is needed to aggregate over all
43: * of the input types (e.g. COUNT()), then it may be convenient
44: * to implement both the AggregateDefinition and the Aggregator
45: * interfaces by the same class.
46: *
47: * @see org.apache.derby.catalog.TypeDescriptor
48: */
49: interface AggregateDefinition {
50: /**
51: * Get the aggregator that performs the aggregation on the
52: * input datatype at execution time. If the input type can be handled,
53: * return a type descriptor with the resultant type information and
54: * fill in the string buffer with the name of the class that
55: * is used to perform the aggregation over the input type.
56: * If the aggregate cannot be performed on this type, then
57: * a null should be returned.
58: * <p>
59: * The aggregator class must implement a zero argument
60: * constructor. The aggregator class can be the same class
61: * as the AggregateDefinition if it implements both interfaces.
62: * <p>
63: * The result datatype may be the same as the input datatype
64: * or a different datatype. To create your own type descriptor
65: * to return to this method, see <i>com.ibm.db2j.types.TypeFactory</i>.
66: *
67: * @param inputType the input type descriptor
68: * @param aggregatorClassName output parameter, filled in
69: * with the class name that implements <i>com.ibm.db2j.aggregates.Aggregator</i>
70: *
71: * @return the output type descriptor (which may or may not
72: * be the same as the input type -- it is ok to simply
73: * return the input type). Null is returned
74: * if the aggregate cannot process the input type.
75: * Note that the output type may be a type that maps
76: * directly to a standard SQL (e.g. <i>java.lang.Integer</i>)
77: * or any other java type (e.g. <i>java.sql.ResultSet</i>,
78: * <i>java.util.Vector</i>, <i>java.util.TimeZone</i> or whatever).
79: * To construct a type descriptor see <i>com.ibm.db2j.types.TypeFactory</i>.
80: *
81: * @see org.apache.derby.catalog.TypeDescriptor
82: *
83: * @exception SQLException Thrown on error.
84: */
85: public TypeDescriptor getAggregator(TypeDescriptor inputType,
86: StringBuffer aggregatorClassName) throws SQLException;
87: }
|