org.apache.derby.impl.sql.execute
Class MaxMinAggregator

java.lang.Object
  extended byorg.apache.derby.impl.sql.execute.SystemAggregator
      extended byorg.apache.derby.impl.sql.execute.OrderableAggregator
          extended byorg.apache.derby.impl.sql.execute.MaxMinAggregator
All Implemented Interfaces:
ExecAggregator, java.io.Externalizable, Formatable, java.io.Serializable, TypedFormat

public final class MaxMinAggregator
extends OrderableAggregator

Aggregator for MAX()/MIN(). Defers most of its work to OrderableAggregator.

Author:
jamie
See Also:
OrderableAggregator, Serialized Form

Field Summary
private  boolean isMax
           
protected  DataValueDescriptor value
           
 
Constructor Summary
MaxMinAggregator()
           
 
Method Summary
protected  void accumulate(DataValueDescriptor addend)
          Accumulate
 void accumulate(DataValueDescriptor addend, java.lang.Object ga)
          Iteratively accumulates the addend into the aggregator.
 boolean didEliminateNulls()
          Return true if the aggregation eliminated at least one null from the input data set.
 java.lang.Object getResult()
          Return the result of the operations that we have been performing.
 int getTypeFormatId()
          Get the formatID which corresponds to this class.
 void merge(ExecAggregator addend)
          Merges one aggregator into a another aggregator.
 ExecAggregator newAggregator()
          Return a new initialized copy of this aggregator, any state set by the setup() method of the original Aggregator must be copied into the new aggregator.
 void readExternal(java.io.ObjectInput in)
           
 void setup(java.lang.String aggregateName)
          Set's up the aggregate for processing.
 void writeExternal(java.io.ObjectOutput out)
          Although we are not expected to be persistent per se, we may be written out by the sorter temporarily.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isMax

private boolean isMax

value

protected DataValueDescriptor value
Constructor Detail

MaxMinAggregator

public MaxMinAggregator()
Method Detail

setup

public void setup(java.lang.String aggregateName)
Description copied from interface: ExecAggregator
Set's up the aggregate for processing.

Specified by:
setup in interface ExecAggregator
Overrides:
setup in class OrderableAggregator

accumulate

protected void accumulate(DataValueDescriptor addend)
                   throws StandardException
Accumulate

Specified by:
accumulate in class SystemAggregator
Parameters:
addend - value to be added in
Throws:
StandardException - on error

newAggregator

public ExecAggregator newAggregator()
Description copied from interface: ExecAggregator
Return a new initialized copy of this aggregator, any state set by the setup() method of the original Aggregator must be copied into the new aggregator.

Returns:
ExecAggregator the new aggregator

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Description copied from class: OrderableAggregator
Although we are not expected to be persistent per se, we may be written out by the sorter temporarily. So we need to be able to write ourselves out and read ourselves back in. We rely on formatable to handle situations where value is null.

Why would we be called to write ourselves out if we are null? For scalar aggregates, we don't bother setting up the aggregator since we only need a single row. So for a scalar aggregate that needs to go to disk, the aggregator might be null.

Specified by:
writeExternal in interface java.io.Externalizable
Overrides:
writeExternal in class OrderableAggregator
Throws:
java.io.IOException - on error
See Also:
Externalizable.writeExternal(java.io.ObjectOutput)

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Overrides:
readExternal in class OrderableAggregator
Throws:
java.io.IOException - on error
java.lang.ClassNotFoundException - on error
See Also:
Externalizable.readExternal(java.io.ObjectInput)

getTypeFormatId

public int getTypeFormatId()
Get the formatID which corresponds to this class.

Returns:
the formatID of this class

merge

public void merge(ExecAggregator addend)
           throws StandardException
Description copied from interface: ExecAggregator
Merges one aggregator into a another aggregator. Merges two partial aggregates results into a single result. Needed for:

An example of a merge would be: given two COUNT() aggregators, C1 and C2, a merge of C1 into C2 would set C1.count += C2.count. So, given a CountAggregator with a getCount() method that returns its counts, its merge method might look like this:


                public void merge(ExecAggregator inputAggregator) throws StandardException
                {
                   count += ((CountAccgregator)inputAggregator).getCount();
                } 

Parameters:
addend - the other Aggregator (input partial aggregate)
Throws:
StandardException - on error
See Also:
ExecAggregator.merge(org.apache.derby.iapi.sql.execute.ExecAggregator)

getResult

public java.lang.Object getResult()
Return the result of the operations that we have been performing. Returns a DataValueDescriptor.

Returns:
the result as a DataValueDescriptor

didEliminateNulls

public boolean didEliminateNulls()
Description copied from interface: ExecAggregator
Return true if the aggregation eliminated at least one null from the input data set.

Specified by:
didEliminateNulls in interface ExecAggregator

accumulate

public void accumulate(DataValueDescriptor addend,
                       java.lang.Object ga)
                throws StandardException
Description copied from interface: ExecAggregator
Iteratively accumulates the addend into the aggregator. Called on each member of the set of values that is being aggregated.

Specified by:
accumulate in interface ExecAggregator
Parameters:
addend - the DataValueDescriptor addend (current input to the aggregation)
ga - a result set getter
Throws:
StandardException - on error


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.