|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--ModSQL.AbstractFunction
|
+--ModSQL.AbstractAggregate
|
+--ModSQL.Aggregate_Math
Implementation of SQL aggregate functions SUM(), AVG() and STDEV(). The return type of each function is function and parameter dependent. AVG() and STDEV() will return type DOUBLE and SUM() will return either type BIGINT or DOUBLE, depending on whether the parameter is an integer or a floating point number, respectively. If there is no parameter, the return type is NULL for all functions. If there are no non-null values to aggregate, SUM() will return 0, but AVG() and STDEV() will return NULL.
| Field Summary | |
static int |
AVG
Function is AVG(). |
private long |
count
Current count of non-null values. |
private int |
op
Which function are we? One of the constants above. |
private int |
return_type
SQL return type for this function. |
static int |
STDEV
Function is STDEV(). |
static int |
SUM
Function is SUM(). |
private double |
sum_double
Current sum as a DOUBLE. |
private long |
sum_long
Current sum as a BIGINT. |
private double |
sum_square
Current sum of squares. |
| Fields inherited from class ModSQL.AbstractAggregate |
distinct, distinct_set |
| Fields inherited from class ModSQL.AbstractFunction |
all_constant, constant_non_null, evaluate_order, evaluate_order_array, out_of_order, parameter_constant, parameter_value, parameters, parameters_array |
| Fields inherited from interface ModSQL.Function |
MATCH_BEGINS, MATCH_EQU, MATCH_GT, MATCH_GTE, MATCH_LT, MATCH_LTE, MATCH_NE |
| Constructor Summary | |
Aggregate_Math(int op)
Constructor. |
|
| Method Summary | |
Object |
evaluate(boolean aggregate)
Evaluate parameters and update count and sums. |
static Function |
forName(String name)
Returns a new instance of this class if name is "sum", "avg", or "stdev". |
String |
functionName()
Returns the name of this function for use by toString() method. |
int |
getMaxResultSize()
Returns -1 as these functions never return String objects. |
int |
getSQLType()
Return the SQL type of the value that this function expects to return. |
void |
optimize()
Prepare the function for use. |
void |
reset()
Resets the current count and sums to zero. |
| Methods inherited from class ModSQL.AbstractAggregate |
addDistinctValue, getDistinctSetSize, isAggregate, isConstant, prefixParameters, registerWith, setDistinct |
| Methods inherited from class ModSQL.AbstractFunction |
addParameter, convertToSQLType, evaluate, evaluateConstantParameters, evaluateOrder, evaluateParameters, evaluateParameters, getCompatableType, getObjectSQLType, getParameter, getParameterCount, postfixParameters, toString |
| Methods inherited from class java.lang.Object |
|
| Methods inherited from interface ModSQL.Function |
addParameter, evaluate, evaluateOrder, getParameter, getParameterCount |
| Field Detail |
public static final int SUM
public static final int AVG
public static final int STDEV
private int op
private int return_type
private long count
private long sum_long
private double sum_double
private double sum_square
| Constructor Detail |
public Aggregate_Math(int op)
op - function type| Method Detail |
public static Function forName(String name)
name - name of function to find
public void optimize()
throws SQLException
Prepare the function for use. All functions accept at most one parameter and require a parameter if DISTINCT is specified. This method also decides on an appropriate return type.
optimize in class AbstractFunctionSQLException - if the parameters are invalidpublic String functionName()
functionName in class AbstractFunction
public int getSQLType()
throws SQLException
public int getMaxResultSize()
public void reset()
throws SQLException
reset in class AbstractAggregateSQLException - if a database error occurs
public Object evaluate(boolean aggregate)
throws SQLException,
EndOfTable
Evaluate parameters and update count and sums. If aggregate is false, the parameter is evaluated and the count and sums are updated, but this method always returns null. If aggregate is true, the parameter is not evaluated, and the current evaluation of the function is returned.
aggregate - true to return final aggregate valueSQLException - if a database-access error occursEndOfTable - if thrown by a parameter
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||