in HSQL/src/org/hsqldb1/SetFunction.java [208:295]
Object getValue() throws HsqlException {
if (setType == Expression.COUNT) {
return ValuePool.getInt(count);
}
if (count == 0) {
return null;
}
switch (setType) {
case Expression.AVG : {
switch (type) {
case Types.TINYINT :
case Types.SMALLINT :
case Types.INTEGER :
return new Long(currentLong / count);
case Types.BIGINT : {
long value = getLongSum().divide(
BigInteger.valueOf(count)).longValue();
return new Long(value);
}
case Types.REAL :
case Types.FLOAT :
case Types.DOUBLE :
return new Double(currentDouble / count);
case Types.NUMERIC :
case Types.DECIMAL :
return currentBigDecimal.divide(new BigDecimal(count),
BigDecimal.ROUND_DOWN);
default :
throw Trace.error(Trace.SUM_OF_NON_NUMERIC);
}
}
case Expression.SUM : {
switch (type) {
case Types.TINYINT :
case Types.SMALLINT :
case Types.INTEGER :
return new Long(currentLong);
case Types.BIGINT :
return new BigDecimal(getLongSum());
case Types.REAL :
case Types.FLOAT :
case Types.DOUBLE :
return new Double(currentDouble);
case Types.NUMERIC :
case Types.DECIMAL :
return currentBigDecimal;
default :
throw Trace.error(Trace.SUM_OF_NON_NUMERIC);
}
}
case Expression.MIN :
case Expression.MAX :
return currentValue;
case Expression.EVERY :
return every ? Boolean.TRUE
: Boolean.FALSE;
case Expression.SOME :
return some ? Boolean.TRUE
: Boolean.FALSE;
case Expression.STDDEV_POP :
case Expression.STDDEV_SAMP :
return getStdDev();
case Expression.VAR_POP :
case Expression.VAR_SAMP :
return getVariance();
default :
throw Trace.error(Trace.INVALID_CONVERSION);
}
}