use of org.apache.derby.iapi.store.access.SortController in project derby by apache.
the class DistinctScalarAggregateResultSet method loadSorter.
// /////////////////////////////////////////////////////////////////////////////
//
// MISC UTILITIES
//
// /////////////////////////////////////////////////////////////////////////////
/**
* 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.
*
* @exception StandardException thrown on failure.
*
* @return the sort controller
*/
private ScanController loadSorter() throws StandardException {
SortController sorter;
ExecRow sourceRow;
ExecIndexRow sortTemplateRow = getRowTemplate();
int inputRowCountEstimate = (int) optimizerEstimatedRowCount;
TransactionController tc = getTransactionController();
/*
** We have a distinct aggregate so, we'll need
** to do a sort. We use all of the sorting columns and
** drop the aggregation on the distinct column. Then
** we'll feed this into the sorter again w/o the distinct
** column in the ordering list.
*/
GenericAggregator[] aggsNoDistinct = getSortAggregators(aggInfoList, true, activation.getLanguageConnectionContext(), source);
SortObserver sortObserver = new AggregateSortObserver(true, aggsNoDistinct, aggregates, sortTemplateRow);
sortId = tc.createSort((Properties) null, sortTemplateRow.getRowArray(), order, sortObserver, // not in order
false, // est rows, -1 means no idea
inputRowCountEstimate, // est rowsize
maxRowSize);
sorter = tc.openSort(sortId);
dropDistinctAggSort = true;
while ((sourceRow = source.getNextRowCore()) != null) {
sorter.insert(sourceRow.getRowArray());
rowsInput++;
}
/*
** End the sort and open up the result set
*/
sorter.completedInserts();
scanController = tc.openSortScan(sortId, activation.getResultSetHoldability());
/*
** Aggs are initialized and input rows
** are in order.
*/
inputRowCountEstimate = rowsInput;
return scanController;
}
use of org.apache.derby.iapi.store.access.SortController in project derby by apache.
the class GroupedAggregateResultSet method loadSorter.
/**
* Load up the sorter. Feed it every row from the
* source scan. When done, close
* the source scan and open the sort. Return the sort
* scan controller.
*
* @exception StandardException thrown on failure.
*
* @return the sort controller
*/
private ScanController loadSorter() throws StandardException {
SortController sorter;
ExecRow inputRow;
int inputRowCountEstimate = (int) optimizerEstimatedRowCount;
ExecIndexRow sortTemplateRow = getRowTemplate();
tc = getTransactionController();
SortObserver observer;
if (usingAggregateObserver)
observer = new AggregateSortObserver(true, aggregates, aggregates, sortTemplateRow);
else
observer = new BasicSortObserver(true, false, sortTemplateRow, true);
genericSortId = tc.createSort((Properties) null, sortTemplateRow.getRowArray(), order, observer, false, // est rows
inputRowCountEstimate, // est rowsize
maxRowSize);
sorter = tc.openSort(genericSortId);
/* The sorter is responsible for doing the cloning */
while ((inputRow = getNextRowFromRS()) != null) {
sorter.insert(inputRow.getRowArray());
}
source.close();
sorter.completedInserts();
sortProperties = sorter.getSortInfo().getAllSortInfo(sortProperties);
if (aggInfoList.hasDistinct()) {
/*
** If there was a distinct aggregate, then that column
** was automatically included as the last column in
** the sort ordering. But we don't want it to be part
** of the ordering anymore, because we aren't grouping
** by that column, we just sorted it so that distinct
** aggregation would see the values in order.
*/
// Although it seems like N aggs could have been
// added at the end, in fact only one has been
// FIXME -- need to get GroupByNode to handle this
// correctly, but that requires understanding
// scalar distinct aggregates.
numDistinctAggs = 1;
}
return tc.openSortScan(genericSortId, activation.getResultSetHoldability());
}
use of org.apache.derby.iapi.store.access.SortController in project derby by apache.
the class SortResultSet method loadSorter.
/**
* Load up the sorter. Feed it every row from the
* source scan. When done, close
* the source scan and open the sort. Return the sort
* scan controller.
*
* @exception StandardException thrown on failure.
*
* @return the sort controller
*/
private ScanController loadSorter() throws StandardException {
SortController sorter;
long sortId;
ExecRow sourceRow;
ExecRow inputRow;
boolean inOrder = (order.length == 0 || isInSortedOrder);
int inputRowCountEstimate = (int) optimizerEstimatedRowCount;
// find the language context and
// Get the current transaction controller
TransactionController tc = getTransactionController();
sortId = tc.createSort((Properties) null, sortTemplateRow.getRowArray(), order, observer, inOrder, // est rows
inputRowCountEstimate, // est rowsize
maxRowSize);
sorter = tc.openSort(sortId);
genericSortId = sortId;
dropGenericSort = true;
/* The sorter is responsible for doing the cloning */
while ((inputRow = getNextRowFromRS()) != null) {
/* The sorter is responsible for doing the cloning */
sorter.insert(inputRow.getRowArray());
}
source.close();
sortProperties = sorter.getSortInfo().getAllSortInfo(sortProperties);
sorter.completedInserts();
return tc.openSortScan(sortId, activation.getResultSetHoldability());
}
Aggregations