Search in sources :

Example 51 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class GroupedAggregateResultSet method getNextRowCore.

/**
 * Return the next row.
 *
 * @exception StandardException thrown on failure.
 * @exception StandardException ResultSetNotOpen thrown if not yet open.
 *
 * @return the next row in the result
 */
public ExecRow getNextRowCore() throws StandardException {
    if (isXplainOnlyMode())
        return null;
    if (!isOpen) {
        return null;
    }
    beginTime = getCurrentTimeMillis();
    if (finishedResults.size() > 0)
        return makeCurrent(finishedResults.remove(0));
    else if (resultsComplete)
        return null;
    ExecIndexRow nextRow = getNextRowFromRS();
    // No rows, no work to do
    if (nextRow == null)
        return finalizeResults();
    // result row from the sorter is complete and ready to return:
    if (usingAggregateObserver)
        return finishAggregation(nextRow);
    /* Drain and merge rows until we find new distinct values for the grouping columns. */
    while (nextRow != null) {
        /* We found a new set of values for the grouping columns.  
			 * Update the current row and return this group. 
			 *
			 * Note that in the case of GROUP BY ROLLUP,
			 * there may be more than one level of grouped
			 * aggregates which is now complete. We can
			 * only return 1, and the other completed
			 * groups are held in finishedResults until
			 * our caller calls getNextRowCore() again to
			 * get the next level of results.
			 */
        ExecIndexRow currSortedRow = resultRows[resultRows.length - 1];
        ExecRow origRow = nextRow.getClone();
        initializeVectorAggregation(nextRow);
        int distinguisherCol = sameGroupingValues(currSortedRow, nextRow);
        for (int r = 0; r < resultRows.length; r++) {
            boolean sameGroup = (rollup ? r <= distinguisherCol : distinguisherCol == numGCols());
            if (sameGroup) {
                /* Same group - initialize the new
					   row and then merge the aggregates */
                // initializeVectorAggregation(nextRow);
                mergeVectorAggregates(nextRow, resultRows[r], r);
            } else {
                setRollupColumnsToNull(resultRows[r], r);
                finishedResults.add(finishAggregation(resultRows[r]));
                /* Save a clone of the new row so
					   that it doesn't get overwritten */
                resultRows[r] = (ExecIndexRow) origRow.getClone();
                initializeVectorAggregation(resultRows[r]);
                initializeDistinctMaps(r, false);
            }
        }
        if (finishedResults.size() > 0) {
            nextTime += getElapsedMillis(beginTime);
            rowsReturned++;
            return makeCurrent(finishedResults.remove(0));
        }
        // Get the next row
        nextRow = getNextRowFromRS();
    }
    return finalizeResults();
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 52 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class GroupedAggregateResultSet method getRowFromSorter.

/**
 * Get a row from the sorter.  Side effects:
 * sets currentRow.
 */
private ExecIndexRow getRowFromSorter() throws StandardException {
    ExecIndexRow inputRow = null;
    if (scanController.next()) {
        // REMIND: HACKALERT we are assuming that result will
        // point to what sortResult is manipulating when
        // we complete the fetch.
        currentRow = sortResultRow;
        inputRow = getExecutionFactory().getIndexableRow(currentRow);
        scanController.fetch(inputRow.getRowArray());
    }
    return inputRow;
}
Also used : ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 53 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class GroupedAggregateResultSet method openCore.

// /////////////////////////////////////////////////////////////////////////////
// 
// ResultSet interface (leftover from NoPutResultSet)
// 
// /////////////////////////////////////////////////////////////////////////////
/**
 * Open the scan.  Load the sorter and prepare to get
 * rows from it.
 *
 * @exception StandardException thrown if cursor finished.
 */
public void openCore() throws StandardException {
    beginTime = getCurrentTimeMillis();
    // is access to open controlled and ensured valid.
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(!isOpen, "GroupedAggregateResultSet already open");
    sortResultRow = (ExecIndexRow) getRowTemplate().getClone();
    sourceExecIndexRow = (ExecIndexRow) getRowTemplate().getClone();
    source.openCore();
    try {
        /* If this is an in-order group by then we do not need the sorter.
		 * (We can do the aggregation ourselves.)
		 * We save a clone of the first row so that subsequent next()s
		 * do not overwrite the saved row.
		 */
        if (!isInSortedOrder)
            scanController = loadSorter();
        ExecIndexRow currSortedRow = getNextRowFromRS();
        resultsComplete = (currSortedRow == null);
        if (usingAggregateObserver) {
            if (currSortedRow != null)
                finishedResults.add(finishAggregation(currSortedRow).getClone());
        } else if (!resultsComplete) {
            if (rollup)
                resultRows = new ExecIndexRow[numGCols() + 1];
            else
                resultRows = new ExecIndexRow[1];
            if (aggInfoList.hasDistinct()) {
                distinctValues = new ArrayList<List<Set<DataValueDescriptor>>>(resultRows.length);
            }
            for (int r = 0; r < resultRows.length; r++) {
                resultRows[r] = (ExecIndexRow) currSortedRow.getClone();
                initializeVectorAggregation(resultRows[r]);
                if (aggInfoList.hasDistinct()) {
                    distinctValues.add(new ArrayList<Set<DataValueDescriptor>>(aggregates.length));
                    initializeDistinctMaps(r, true);
                }
            }
        }
    } catch (StandardException e) {
        // DERBY-4330 Result set tree must be atomically open or
        // closed for reuse to work (after DERBY-827).
        // to make close do its thing:
        isOpen = true;
        try {
            close();
        } catch (StandardException ee) {
        }
        throw e;
    }
    isOpen = true;
    numOpens++;
    openTime += getElapsedMillis(beginTime);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) Set(java.util.Set) HashSet(java.util.HashSet) NoPutResultSet(org.apache.derby.iapi.sql.execute.NoPutResultSet) CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) ArrayList(java.util.ArrayList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 54 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class GroupedAggregateResultSet method getRowFromResultSet.

/**
 * Get a row from the input result set.
 */
private ExecIndexRow getRowFromResultSet() throws StandardException {
    ExecRow sourceRow;
    ExecIndexRow inputRow = null;
    if ((sourceRow = source.getNextRowCore()) != null) {
        rowsInput++;
        sourceExecIndexRow.execRowToExecIndexRow(sourceRow);
        inputRow = sourceExecIndexRow;
    }
    return inputRow;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 55 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class HashScanResultSet method printPosition.

/**
 * Return a start or stop positioner as a String.
 */
private String printPosition(int searchOperator, GeneratedMethod positionGetter, ExecIndexRow eiRow) {
    String idt = "";
    String output = "";
    if (positionGetter == null) {
        return "\t" + MessageService.getTextMessage(SQLState.LANG_NONE) + "\n";
    }
    ExecIndexRow positioner = null;
    try {
        positioner = (ExecIndexRow) positionGetter.invoke(activation);
    } catch (StandardException e) {
        if (eiRow == null) {
            return "\t" + MessageService.getTextMessage(SQLState.LANG_POSITION_NOT_AVAIL);
        }
        return "\t" + MessageService.getTextMessage(SQLState.LANG_UNEXPECTED_EXC_GETTING_POSITIONER) + "\n";
    }
    if (positioner == null) {
        return "\t" + MessageService.getTextMessage(SQLState.LANG_NONE) + "\n";
    }
    String searchOp = null;
    switch(searchOperator) {
        case ScanController.GE:
            searchOp = ">=";
            break;
        case ScanController.GT:
            searchOp = ">";
            break;
        default:
            if (SanityManager.DEBUG) {
                SanityManager.THROWASSERT("Unknown search operator " + searchOperator);
            }
            // This is not internationalized because we should never
            // reach here.
            searchOp = "unknown value (" + searchOperator + ")";
            break;
    }
    output += "\t" + MessageService.getTextMessage(SQLState.LANG_POSITIONER, searchOp, String.valueOf(positioner.nColumns())) + "\n";
    output += "\t" + MessageService.getTextMessage(SQLState.LANG_ORDERED_NULL_SEMANTICS) + "\n";
    boolean colSeen = false;
    for (int position = 0; position < positioner.nColumns(); position++) {
        if (positioner.areNullsOrdered(position)) {
            output = output + position + " ";
            colSeen = true;
        }
        if (colSeen && position == positioner.nColumns() - 1) {
            output = output + "\n";
        }
    }
    return output;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Aggregations

ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)110 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)72 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)34 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)30 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)27 SQLChar (org.apache.derby.iapi.types.SQLChar)22 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)14 SQLLongint (org.apache.derby.iapi.types.SQLLongint)13 RowLocation (org.apache.derby.iapi.types.RowLocation)12 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)10 ScanController (org.apache.derby.iapi.store.access.ScanController)9 UUID (org.apache.derby.catalog.UUID)8 ArrayList (java.util.ArrayList)7 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)6 ConglomerateDescriptorList (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList)6 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)6 TransactionController (org.apache.derby.iapi.store.access.TransactionController)6 Properties (java.util.Properties)5 PermissionsDescriptor (org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor)5 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)5