Package edu.caltech.nanodb.functions
Class MinMaxAggregate
- java.lang.Object
-
- edu.caltech.nanodb.functions.Function
-
- edu.caltech.nanodb.functions.ScalarFunction
-
- edu.caltech.nanodb.functions.AggregateFunction
-
- edu.caltech.nanodb.functions.MinMaxAggregate
-
- All Implemented Interfaces:
java.lang.Cloneable
public class MinMaxAggregate extends AggregateFunction
This aggregate function can be used to compute either the minimum or the maximum of a collection of values.
-
-
Field Summary
Fields Modifier and Type Field Description private int
minimumSwitch
This value is set to 1 if the aggregate function is computing the minimum value, or -1 if the aggregate function is computing the maximum value.private java.lang.Comparable
result
The actual result of the aggregate function, or null if the function hasn't been handed a non-NULL value yet.
-
Constructor Summary
Constructors Constructor Description MinMaxAggregate(boolean minimum)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addValue(java.lang.Object value)
Adds a value to the aggregate function so that it can update its internal state.void
clearResult()
Clears the aggregate function's current state so that the object can be reused to compute an aggregate on another set of input values.java.lang.Object
getResult()
Returns the aggregated result computed for this aggregate function.ColumnType
getReturnType(java.util.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 Detail
-
minimumSwitch
private int minimumSwitch
This value is set to 1 if the aggregate function is computing the minimum value, or -1 if the aggregate function is computing the maximum value. It is used to avoid having another conditional in theaddValue(java.lang.Object)
implementation.
-
result
private java.lang.Comparable result
The actual result of the aggregate function, or null if the function hasn't been handed a non-NULL value yet.
-
-
Method Detail
-
clearResult
public void clearResult()
Description copied from class:AggregateFunction
Clears 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:
clearResult
in classAggregateFunction
-
addValue
public void addValue(java.lang.Object value)
Description copied from class:AggregateFunction
Adds a value to the aggregate function so that it can update its internal state. Generally, aggregate functions ignorenull
inputs (which represent SQL NULL values) when computing their results.- Specified by:
addValue
in classAggregateFunction
- Parameters:
value
- the value to add to the aggregate function
-
getResult
public java.lang.Object getResult()
Description copied from class:AggregateFunction
Returns 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:
getResult
in classAggregateFunction
- Returns:
- the result of the aggregate computation.
-
getReturnType
public ColumnType getReturnType(java.util.List<Expression> args, Schema schema)
Description copied from class:ScalarFunction
Returns the column type of the resulting column after applying the function. This generally depends on the column type of the inputs.- Specified by:
getReturnType
in classScalarFunction
- Parameters:
args
- the arguments to the function callschema
- the schema of the table- Returns:
- the column type of the resulting column
-
-