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

java.lang.Object
  extended by org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
      extended by org.apache.derby.impl.sql.execute.NoPutResultSetImpl
          extended by org.apache.derby.impl.sql.execute.GenericAggregateResultSet
              extended by org.apache.derby.impl.sql.execute.ScalarAggregateResultSet
All Implemented Interfaces:
CursorResultSet, NoPutResultSet, ResultSet, RowLocationRetRowSource, RowSource
Direct Known Subclasses:
DistinctScalarAggregateResultSet

 class ScalarAggregateResultSet
extends GenericAggregateResultSet
implements CursorResultSet

This ResultSet evaluates scalar, non distinct aggregates. It will scan the entire source result set and calculate the scalar aggregates when scanning the source during the first call to next().


Field Summary
protected  int countOfRows
           
protected  boolean isInSortedOrder
           
private  boolean nextSatisfied
           
 int rowsInput
           
 boolean singleInputRow
           
protected  ExecIndexRow sortTemplateRow
           
protected  ExecIndexRow sourceExecIndexRow
           
 
Fields inherited from class org.apache.derby.impl.sql.execute.GenericAggregateResultSet
aggInfoList, aggregates, originalSource, rowAllocator, source
 
Fields inherited from class org.apache.derby.impl.sql.execute.NoPutResultSetImpl
checkNullCols, clonedExecRow, cncLen, resultSetNumber, targetResultSet
 
Fields inherited from class org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
activation, beginTime, closeTime, compactRow, constructorTime, currentRow, endExecutionTime, finished, isOpen, isTopResultSet, nextTime, numOpens, openTime, optimizerEstimatedCost, optimizerEstimatedRowCount, resultDescription, rowsFiltered, rowsSeen, startExecutionTime, subqueryTrackingArray
 
Fields inherited from interface org.apache.derby.iapi.sql.ResultSet
CURRENT_RESULTSET_ONLY, ENTIRE_RESULTSET_TREE, ISAFTERLAST, ISBEFOREFIRST, ISFIRST, ISLAST
 
Fields inherited from interface org.apache.derby.iapi.sql.execute.NoPutResultSet
ABSOLUTE, FIRST, LAST, NEXT, PREVIOUS, RELATIVE
 
Constructor Summary
ScalarAggregateResultSet(NoPutResultSet s, boolean isInSortedOrder, int aggregateItem, Activation a, GeneratedMethod ra, int resultSetNumber, boolean singleInputRow, double optimizerEstimatedRowCount, double optimizerEstimatedCost)
          Constructor
 
Method Summary
protected  void accumulateScalarAggregation(ExecRow inputRow, ExecRow accumulateRow, boolean hasDistinctAggregates)
          Run accumulation on every aggregate in this row.
 void close()
          If the result set has been opened, close the open scan.
 ExecRow getCurrentRow()
          This result set has its row from the last fetch done.
 ExecRow getNextRowCore()
          Return the next row.
 ExecIndexRow getRowFromResultSet(boolean doClone)
          Get a row from the input result set.
 RowLocation getRowLocation()
          This result set has its row location from the last fetch done.
 long getTimeSpent(int type)
          Return the total amount of time spent in this ResultSet
private  void initializeScalarAggregation(ExecRow row)
           
 void openCore()
          Open the scan.
 void reopenCore()
          reopen a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...
 
Methods inherited from class org.apache.derby.impl.sql.execute.GenericAggregateResultSet
finish, finishAggregation, getSortAggregators
 
Methods inherited from class org.apache.derby.impl.sql.execute.NoPutResultSetImpl
clearCurrentRow, clearOrderableCache, closeRowSource, getCursorName, getNextRowFromRowSource, getResultDescription, getValidColumns, isForUpdate, markRowAsDeleted, needsRowLocation, needsToClone, positionScanAtRowLocation, printQualifiers, resultSetNumber, rowLocation, setCurrentRow, setNeedsRowLocation, setTargetResultSet, skipRow, skipScan, updateRow
 
Methods inherited from class org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
addWarning, attachStatementContext, checkCancellationFlag, checkRowPosition, cleanUp, dumpTimeStats, finishAndRTS, getAbsoluteRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCompactRow, getCurrentTimeMillis, getElapsedMillis, getEndExecutionTimestamp, getEstimatedRowCount, getExecuteTime, getExecutionFactory, getFirstRow, getLanguageConnectionContext, getLastRow, getNextRow, getPointOfAttachment, getPreviousRow, getRelativeRow, getRowNumber, getScanIsolationLevel, getSubqueryTrackingArray, getTransactionController, getWarnings, isClosed, markAsTopResultSet, modifiedRowCount, open, recordConstructorTime, requiresRelocking, returnsRows, setAfterLastRow, setBeforeFirstRow, setCompactRow, setCompatRow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.sql.ResultSet
checkRowPosition, cleanUp, clearCurrentRow, finish, getAbsoluteRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCursorName, getEndExecutionTimestamp, getExecuteTime, getFirstRow, getLastRow, getNextRow, getPreviousRow, getRelativeRow, getResultDescription, getRowNumber, getSubqueryTrackingArray, getWarnings, isClosed, modifiedRowCount, open, returnsRows, setAfterLastRow, setBeforeFirstRow
 

Field Detail

rowsInput

public int rowsInput

singleInputRow

public boolean singleInputRow

sortTemplateRow

protected ExecIndexRow sortTemplateRow

isInSortedOrder

protected boolean isInSortedOrder

sourceExecIndexRow

protected ExecIndexRow sourceExecIndexRow

nextSatisfied

private boolean nextSatisfied

countOfRows

protected int countOfRows
Constructor Detail

ScalarAggregateResultSet

ScalarAggregateResultSet(NoPutResultSet s,
                         boolean isInSortedOrder,
                         int aggregateItem,
                         Activation a,
                         GeneratedMethod ra,
                         int resultSetNumber,
                         boolean singleInputRow,
                         double optimizerEstimatedRowCount,
                         double optimizerEstimatedCost)
                   throws StandardException
Constructor

Parameters:
s - input result set
isInSortedOrder - true if the source results are in sorted order
aggregateItem - indicates the number of the SavedObject off of the PreparedStatement that holds the AggregatorInfoList used by this routine.
a - activation
ra - generated method to build an empty output row
resultSetNumber - The resultSetNumber for this result set
Throws:
StandardException - Thrown on error
Method Detail

openCore

public void openCore()
              throws StandardException
Open the scan. Load the sorter and prepare to get rows from it.

Specified by:
openCore in interface NoPutResultSet
Throws:
StandardException - thrown if cursor finished.

getNextRowCore

public ExecRow getNextRowCore()
                       throws StandardException
Return the next row. If it is a scalar aggregate scan

Specified by:
getNextRowCore in interface NoPutResultSet
Specified by:
getNextRowCore in class BasicNoPutResultSetImpl
Returns:
the next row in the result
Throws:
StandardException - thrown on failure.
StandardException - ResultSetNotOpen thrown if not yet open.
See Also:
NoPutResultSet.getNextRowCore()

close

public void close()
           throws StandardException
If the result set has been opened, close the open scan.

Specified by:
close in interface ResultSet
Overrides:
close in class NoPutResultSetImpl
Throws:
StandardException - thrown on error

getTimeSpent

public long getTimeSpent(int type)
Return the total amount of time spent in this ResultSet

Specified by:
getTimeSpent in interface ResultSet
Parameters:
type - CURRENT_RESULTSET_ONLY - time spent only in this ResultSet ENTIRE_RESULTSET_TREE - time spent in this ResultSet and below.
Returns:
long The total amount of time spent (in milliseconds).

getRowLocation

public RowLocation getRowLocation()
                           throws StandardException
This result set has its row location from the last fetch done. Always returns null.

Specified by:
getRowLocation in interface CursorResultSet
Returns:
the row location of the current cursor row.
Throws:
StandardException - thrown on failure to get row location
See Also:
CursorResultSet

getCurrentRow

public ExecRow getCurrentRow()
                      throws StandardException
This result set has its row from the last fetch done. If the cursor is closed, a null is returned.

Specified by:
getCurrentRow in interface CursorResultSet
Returns:
the last row returned;
Throws:
StandardException - thrown on failure.
See Also:
CursorResultSet

getRowFromResultSet

public ExecIndexRow getRowFromResultSet(boolean doClone)
                                 throws StandardException
Get a row from the input result set.

Parameters:
doClone - - true of the row should be cloned
Throws:
StandardException - Thrown on error

reopenCore

public void reopenCore()
                throws StandardException
reopen a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...

Specified by:
reopenCore in interface NoPutResultSet
Overrides:
reopenCore in class BasicNoPutResultSetImpl
Throws:
StandardException - thrown if cursor finished.
See Also:
NoPutResultSet.openCore()

accumulateScalarAggregation

protected void accumulateScalarAggregation(ExecRow inputRow,
                                           ExecRow accumulateRow,
                                           boolean hasDistinctAggregates)
                                    throws StandardException
Run accumulation on every aggregate in this row. This method is useful when draining the source or sorter, depending on whether or not there were any distinct aggregates. Remember, if there are distinct aggregates, then the non-distinct aggregates were calculated on the way into the sorter and only the distinct aggregates will be accumulated here. Otherwise, all aggregates will be accumulated here.

Parameters:
inputRow - the input row
accumulateRow - the row with the accumulator (may be the same as the input row.
hasDistinctAggregates - does this scan have distinct aggregates. Used to figure out whether to merge or accumulate nondistinct aggregates.
Throws:
StandardException - Thrown on error

initializeScalarAggregation

private void initializeScalarAggregation(ExecRow row)
                                  throws StandardException
Throws:
StandardException

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.