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

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

public class DistinctScalarAggregateResultSet
extends ScalarAggregateResultSet

This ResultSet evaluates scalar aggregates where 1 (or more, in the future) of the aggregates are distinct. It will scan the entire source result set and calculate the scalar aggregates when scanning the source during the first call to next().

Author:
jerry (broken out from SortResultSet)

Field Summary
private  boolean dropDistinctAggSort
           
private  int maxRowSize
           
private  ColumnOrdering[] order
           
private  ScanController scanController
           
private  boolean sorted
           
private  long sortId
           
private  ExecIndexRow sortResultRow
           
 
Fields inherited from class org.apache.derby.impl.sql.execute.ScalarAggregateResultSet
activation, aggInfoList, aggregates, beginTime, checkGM, checkNullCols, clonedExecRow, closeCleanup, closeTime, cncLen, compactRow, constructorTime, countOfRows, currentRow, endExecutionTime, finished, heapConglomerate, indent, isInSortedOrder, isOpen, isTopResultSet, lcc, nextTime, numOpens, openTime, optimizerEstimatedCost, optimizerEstimatedRowCount, originalSource, resultDescription, resultSetNumber, rowAllocator, rowsFiltered, rowsInput, rowsSeen, singleInputRow, sortTemplateRow, source, sourceDepth, sourceExecIndexRow, startExecutionTime, subIndent, subqueryTrackingArray, targetResultSet
 
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
DistinctScalarAggregateResultSet(NoPutResultSet s, boolean isInSortedOrder, int aggregateItem, int orderingItem, Activation a, GeneratedMethod ra, int maxRowSize, int resultSetNumber, boolean singleInputRow, double optimizerEstimatedRowCount, double optimizerEstimatedCost, GeneratedMethod c)
          Constructor
 
Method Summary
protected  void closeSource()
          Close the source of whatever we have been scanning.
 ExecRow getNextRowCore()
          Return the next row.
 ExecIndexRow getRowFromResultSet(boolean doClone)
          Get a row from the sorter.
private  ScanController loadSorter()
          Load up the sorter.
 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.ScalarAggregateResultSet
accumulateScalarAggregation, addWarning, attachStatementContext, checkRowPosition, cleanUp, clearCurrentRow, clearOrderableCache, close, closeRowSource, dumpTimeStats, finish, finishAggregation, finishAndRTS, getAbsoluteRow, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCompactRow, getCurrentRow, getCurrentTimeMillis, getCursorName, getElapsedMillis, getEndExecutionTimestamp, getEstimatedRowCount, getExecuteTime, getExecutionFactory, getFirstRow, getLanguageConnectionContext, getLastRow, getNextRow, getNextRowFromRowSource, getPointOfAttachment, getPreviousRow, getRelativeRow, getResultDescription, getRowLocation, getRowNumber, getScanIsolationLevel, getSortAggregators, getSubqueryTrackingArray, getTimeSpent, getTransactionController, getValidColumns, getWarnings, isClosed, isForUpdate, markAsTopResultSet, modifiedRowCount, needsRowLocation, needsToClone, open, printQualifiers, requiresRelocking, resultSetNumber, returnsRows, rowLocation, setAfterLastRow, setBeforeFirstRow, setCheckConstraints, setCompactRow, setCompatRow, setCurrentRow, setHeapConglomerate, setNeedsRowLocation, setTargetResultSet, skipRow, skipScan
 
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, finish, getAbsoluteRow, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCursorName, getEndExecutionTimestamp, getExecuteTime, getFirstRow, getLastRow, getNextRow, getPreviousRow, getRelativeRow, getResultDescription, getRowNumber, getSubqueryTrackingArray, getWarnings, isClosed, modifiedRowCount, open, returnsRows, setAfterLastRow, setBeforeFirstRow
 

Field Detail

order

private ColumnOrdering[] order

maxRowSize

private int maxRowSize

dropDistinctAggSort

private boolean dropDistinctAggSort

sortId

private long sortId

scanController

private ScanController scanController

sortResultRow

private ExecIndexRow sortResultRow

sorted

private boolean sorted
Constructor Detail

DistinctScalarAggregateResultSet

public DistinctScalarAggregateResultSet(NoPutResultSet s,
                                        boolean isInSortedOrder,
                                        int aggregateItem,
                                        int orderingItem,
                                        Activation a,
                                        GeneratedMethod ra,
                                        int maxRowSize,
                                        int resultSetNumber,
                                        boolean singleInputRow,
                                        double optimizerEstimatedRowCount,
                                        double optimizerEstimatedCost,
                                        GeneratedMethod c)
                                 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
Overrides:
openCore in class ScalarAggregateResultSet
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
Overrides:
getNextRowCore in class ScalarAggregateResultSet
Returns:
the next row in the result
Throws:
StandardException - thrown on failure.
StandardException - ResultSetNotOpen thrown if not yet open.

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 ScalarAggregateResultSet
Throws:
StandardException - thrown if cursor finished.

getRowFromResultSet

public ExecIndexRow getRowFromResultSet(boolean doClone)
                                 throws StandardException
Get a row from the sorter. Side effects: sets currentRow.

Overrides:
getRowFromResultSet in class ScalarAggregateResultSet
Parameters:
doClone - - true of the row should be cloned
Throws:
StandardException - Thrown on error

closeSource

protected void closeSource()
                    throws StandardException
Close the source of whatever we have been scanning.

Throws:
StandardException - thrown on error

loadSorter

private ScanController loadSorter()
                           throws StandardException
Load up the sorter. Feed it every row from the source scan. If we have a vector aggregate, initialize the aggregator for each source row. When done, close the source scan and open the sort. Return the sort scan controller.

Returns:
the sort controller
Throws:
StandardException - thrown on failure.


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