Package org.apache.derby.iapi.store.access

Examples of org.apache.derby.iapi.store.access.SortController


                               GroupFetchScanController scan,
                               long sortId,
                               RowLocation rl[])
    throws StandardException
  {
    SortController    sorter;
    long        rowCount = 0;

    sorter = tc.openSort(sortId);

    try
    {
      // Step through all the rows in the base table
      // prepare an array or rows for bulk fetch
      int bulkFetchSize = baseRows.length;

      if (SanityManager.DEBUG)
      {
        SanityManager.ASSERT(bulkFetchSize == indexRows.length,
          "number of base rows and index rows does not match");
        SanityManager.ASSERT(bulkFetchSize == rl.length,
          "number of base rows and row locations does not match");
      }

      DataValueDescriptor[][] baseRowArray = new DataValueDescriptor[bulkFetchSize][];

      for (int i = 0; i < bulkFetchSize; i++)
        baseRowArray[i] = baseRows[i].getRowArray();

      // rl[i] and baseRowArray[i] and indexRows[i] are all tied up
      // beneath the surface.  Fetching the base row and row location
      // from the table scan will automagically set up the indexRow
      // fetchNextGroup will return how many rows are actually fetched.
      int bulkFetched = 0;

      while ((bulkFetched = scan.fetchNextGroup(baseRowArray, rl)) > 0)
      {
        for (int i = 0; i < bulkFetched; i++)
        {
          sorter.insert(indexRows[i].getRowArray());
          rowCount++;
        }
      }

      /*
      ** We've just done a full scan on the heap, so set the number
      ** of rows so the optimizer will have an accurate count.
      */
      scan.setEstimatedRowCount(rowCount);
    }
    finally
    {
      sorter.completedInserts();
    }

    return new CardinalityCounter(tc.openSortRowSource(sortId));
  }
View Full Code Here


   * @return  the sort controller
    */
  private ScanController loadSorter()
    throws StandardException
  {
    SortController       sorter;
    long           sortId;
    ExecRow         sourceRow;
    ExecRow         inputRow;
    int            inputRowCountEstimate = (int) optimizerEstimatedRowCount;
    boolean          inOrder = isInSortedOrder;

    tc = getTransactionController();

    ColumnOrdering[] currentOrdering = order;

    /*
    ** Do we have any distinct aggregates?  If so, we'll need
    ** a separate 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.
    */
    if (aggInfoList.hasDistinct())
    {
      hasDistinctAggregate = true;
     
      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,
          false,      // not in order
          inputRowCountEstimate,        // est rows, -1 means no idea 
          maxRowSize    // est rowsize
          );
      sorter = tc.openSort(sortId);
      distinctAggSortId = sortId;
      dropDistinctAggSort = true;
       
      while ((sourceRow = source.getNextRowCore())!=null)
      {
        sorter.insert(sourceRow.getRowArray());
        rowsInput++;
      }

      /*
      ** End the sort and open up the result set
      */
      source.close();
      sortProperties = sorter.getSortInfo().getAllSortInfo(sortProperties);
      sorter.completedInserts();

      scanController =
                tc.openSortScan(sortId, activation.getResultSetHoldability());
     
      /*
      ** Aggs are initialized and input rows
      ** are in order.  All we have to do is
      ** another sort to remove (merge) the
      ** duplicates in the distinct column
      */ 
      inOrder = true;
      inputRowCountEstimate = rowsInput;
 
      /*
      ** Drop the last column from the ordering.  The
      ** last column is the distinct column.  Don't
      ** pay any attention to the fact that the ordering
      ** object's name happens to correspond to a techo
      ** band from the 80's.
      **
      ** If there aren't any ordering columns other
      ** than the distinct (i.e. for scalar distincts)
      ** just skip the 2nd sort altogether -- we'll
      ** do the aggregate merge ourselves rather than
      ** force a 2nd sort.
      */
      if (order.length == 1)
      {
        return scanController;
      }

      ColumnOrdering[] newOrder = new ColumnOrdering[order.length - 1];
      System.arraycopy(order, 0, newOrder, 0, order.length - 1);
      currentOrdering = newOrder;
    }

    SortObserver sortObserver = new AggregateSortObserver(true, aggregates, aggregates,
                                sortTemplateRow);

    sortId = tc.createSort((Properties)null,
            sortTemplateRow.getRowArray(),
            currentOrdering,
            sortObserver,
            inOrder,
            inputRowCountEstimate, // est rows
             maxRowSize      // est rowsize
            );
    sorter = tc.openSort(sortId);
    genericSortId = sortId;
    dropGenericSort = true;
 
    /* The sorter is responsible for doing the cloning */
    while ((inputRow = getNextRowFromRS()) != null)
    {
      sorter.insert(inputRow.getRowArray());
    }
    source.close();
    sortProperties = sorter.getSortInfo().getAllSortInfo(sortProperties);
    sorter.completedInserts();

    return tc.openSortScan(sortId, activation.getResultSetHoldability());
  }
View Full Code Here

   * @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,
            inputRowCountEstimate, // est rows
             maxRowSize      // est rowsize
            );
    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());
  }
View Full Code Here

   * @return  the sort controller
    */
  private ScanController loadSorter()
    throws StandardException
  {
    SortController       sorter;
    ExecRow         sourceRow;
    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,
          false,      // not in order
          inputRowCountEstimate,        // est rows, -1 means no idea 
          maxRowSize    // est rowsize
          );
    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());
     
    /*
 
View Full Code Here

            {
                // Loop from the end since the call to close() will remove the
                // element from the list.
                for (int i = sortControllers.size() - 1; i >= 0; i--)
                {
                    SortController sc = (SortController) sortControllers.get(i);
                    sc.completedInserts();
                }
                sortControllers.clear();
            }
        }
View Full Code Here

            if (sortControllers != null)
            {
                for (Iterator it = sortControllers.iterator(); it.hasNext(); )
                {
                    SortController sc = (SortController) it.next();
                    str += "open sort controller: " + sc + "\n";
                }
            }

            if (sorts != null)
View Full Code Here

      throw StandardException.newException(
                    SQLState.AM_NO_SUCH_SORT, new Long(id));
    }

    // Open it.
    SortController sc = sort.open(this);

    // Keep track of it so we can release on close.
    if (sortControllers == null)
      sortControllers = new ArrayList();
    sortControllers.add(sc);
View Full Code Here

            if (closeHeldControllers)
            {
                e = sortControllers.elements();
                while (e.hasMoreElements())
                {
                    SortController sc = (SortController) e.nextElement();
                    sc.close();
                }
                sortControllers.removeAllElements();
            }
        }
View Full Code Here

            if (sortControllers != null)
            {
                e = sortControllers.elements();
                while (e.hasMoreElements())
                {
                    SortController sc = (SortController) e.nextElement();
                    str += "open sort controller: " + sc + "\n";
                }
            }

            if (sorts != null)
View Full Code Here

      throw StandardException.newException(
                    SQLState.AM_NO_SUCH_SORT, new Long(id));
    }

    // Open it.
    SortController sc = sort.open(this);

    // Keep track of it so we can release on close.
    if (sortControllers == null)
      sortControllers = new Vector();
    sortControllers.addElement(sc);
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.store.access.SortController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.