Package edu.caltech.nanodb.functions
Class SumAvgAggregate
java.lang.Object
edu.caltech.nanodb.functions.Function
edu.caltech.nanodb.functions.ScalarFunction
edu.caltech.nanodb.functions.AggregateFunction
edu.caltech.nanodb.functions.SumAvgAggregate
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
Avg,AvgDistinct,Sum,SumDistinct
This aggregate function can be used to compute both SUM and
AVERAGE functions. It computes both the sum and average of a
collection of values.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanThis value is set to true if we want to compute the average value.private intThe current count of items that have been addedprivate booleanIndicates whether we want distinct values or notSet to keep track of distinct valuesprivate ObjectContains the actual value of the sum -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a value to the aggregate function so that it can update its internal state.voidClears the aggregate function's current state so that the object can be reused to compute an aggregate on another set of input values.Returns the aggregated result computed for this aggregate function.getReturnType(List<Expression> args, Schema schema) Returns the column type of the resulting column after applying the function.Methods inherited from class edu.caltech.nanodb.functions.AggregateFunction
supportsDistinct
-
Field Details
-
computeAverage
private boolean computeAverageThis value is set to true if we want to compute the average value. Otherwise, we compute the sum. -
sum
Contains the actual value of the sum -
count
private int countThe current count of items that have been added -
distinct
private boolean distinctIndicates whether we want distinct values or not -
set
Set to keep track of distinct values
-
-
Constructor Details
-
SumAvgAggregate
public SumAvgAggregate(boolean computeAverage, boolean distinct)
-
-
Method Details
-
clearResult
public void clearResult()Description copied from class:AggregateFunctionClears the aggregate function's current state so that the object can be reused to compute an aggregate on another set of input values.- Specified by:
clearResultin classAggregateFunction
-
addValue
Description copied from class:AggregateFunctionAdds a value to the aggregate function so that it can update its internal state. Generally, aggregate functions ignorenullinputs (which represent SQL NULL values) when computing their results.- Specified by:
addValuein classAggregateFunction- Parameters:
value- the value to add to the aggregate function
-
getResult
Description copied from class:AggregateFunctionReturns the aggregated result computed for this aggregate function. Generally, if aggregate functions receive no non-null inputs then they should produce a null result. (COUNT is an exception to this rule, producing 0 in that case.)- Specified by:
getResultin classAggregateFunction- Returns:
- the result of the aggregate computation.
-
getReturnType
Description copied from class:ScalarFunctionReturns the column type of the resulting column after applying the function. This generally depends on the column type of the inputs.- Specified by:
getReturnTypein classScalarFunction- Parameters:
args- the arguments to the function callschema- the schema of the table- Returns:
- the column type of the resulting column
-