Search in sources :

Example 6 with SortController

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;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) TransactionController(org.apache.derby.iapi.store.access.TransactionController) Properties(java.util.Properties) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SortObserver(org.apache.derby.iapi.store.access.SortObserver) SortController(org.apache.derby.iapi.store.access.SortController)

Example 7 with SortController

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());
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) Properties(java.util.Properties) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SortObserver(org.apache.derby.iapi.store.access.SortObserver) SortController(org.apache.derby.iapi.store.access.SortController)

Example 8 with SortController

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());
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) TransactionController(org.apache.derby.iapi.store.access.TransactionController) Properties(java.util.Properties) SortController(org.apache.derby.iapi.store.access.SortController)

Aggregations

SortController (org.apache.derby.iapi.store.access.SortController)8 Properties (java.util.Properties)4 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)4 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)3 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)3 SortObserver (org.apache.derby.iapi.store.access.SortObserver)3 Sort (org.apache.derby.iapi.store.access.conglomerate.Sort)3 TransactionController (org.apache.derby.iapi.store.access.TransactionController)2 ScanManager (org.apache.derby.iapi.store.access.conglomerate.ScanManager)2 ArrayList (java.util.ArrayList)1 UUID (org.apache.derby.catalog.UUID)1 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)1 LanguageProperties (org.apache.derby.iapi.sql.LanguageProperties)1 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)1 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)1 IndexRowGenerator (org.apache.derby.iapi.sql.dictionary.IndexRowGenerator)1 ColumnOrdering (org.apache.derby.iapi.store.access.ColumnOrdering)1 GroupFetchScanController (org.apache.derby.iapi.store.access.GroupFetchScanController)1 ScanController (org.apache.derby.iapi.store.access.ScanController)1 Conglomerate (org.apache.derby.iapi.store.access.conglomerate.Conglomerate)1