Search in sources :

Example 1 with NoPutResultSet

use of org.apache.derby.iapi.sql.execute.NoPutResultSet 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 2 with NoPutResultSet

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

the class ScrollInsensitiveResultSet method positionInLastFetchedRow.

/**
 * Positions the cursor in the last fetched row. This is done before
 * navigating to a row that has not previously been fetched, so that
 * getNextRowCore() will re-start from where it stopped.
 */
private void positionInLastFetchedRow() throws StandardException {
    if (positionInSource > 0) {
        positionInHashTable.setValue(positionInSource);
        DataValueDescriptor[] hashRowArray = getCurrentRowFromHashtable();
        RowLocation rowLoc = (RowLocation) hashRowArray[POS_ROWLOCATION];
        ((NoPutResultSet) target).positionScanAtRowLocation(rowLoc);
        currentPosition = positionInSource;
    }
}
Also used : NoPutResultSet(org.apache.derby.iapi.sql.execute.NoPutResultSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 3 with NoPutResultSet

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

the class CursorActivation method decorateResultSet.

/**
 * @see BaseActivation#decorateResultSet
 */
ResultSet decorateResultSet() throws StandardException {
    // CursorActivation means it's a query that returns rows. Check that
    // the caller is authorized to run SQL read operations.
    getLanguageConnectionContext().getAuthorizer().authorize(this, Authorizer.SQL_SELECT_OP);
    // The top-level result set should be marked as such.
    NoPutResultSet rs = (NoPutResultSet) createResultSet();
    rs.markAsTopResultSet();
    return rs;
}
Also used : NoPutResultSet(org.apache.derby.iapi.sql.execute.NoPutResultSet)

Example 4 with NoPutResultSet

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

the class RealResultSetStatisticsFactory method getRunTimeStatistics.

// 
// ExecutionFactory interface
// 
// 
// ResultSetStatisticsFactory interface
// 
/**
 *		@see ResultSetStatisticsFactory#getRunTimeStatistics
 */
public RunTimeStatistics getRunTimeStatistics(Activation activation, ResultSet rs, NoPutResultSet[] subqueryTrackingArray) throws StandardException {
    PreparedStatement preStmt = activation.getPreparedStatement();
    // In this case statistics should not be generated.
    if (preStmt == null)
        return null;
    ResultSetStatistics topResultSetStatistics;
    if (rs instanceof NoPutResultSet) {
        topResultSetStatistics = getResultSetStatistics((NoPutResultSet) rs);
    } else {
        topResultSetStatistics = getResultSetStatistics(rs);
    }
    /* Build up the info on the materialized subqueries */
    int subqueryTrackingArrayLength = (subqueryTrackingArray == null) ? 0 : subqueryTrackingArray.length;
    ResultSetStatistics[] subqueryRSS = new ResultSetStatistics[subqueryTrackingArrayLength];
    boolean anyAttached = false;
    for (int index = 0; index < subqueryTrackingArrayLength; index++) {
        if (subqueryTrackingArray[index] != null && subqueryTrackingArray[index].getPointOfAttachment() == -1) {
            subqueryRSS[index] = getResultSetStatistics(subqueryTrackingArray[index]);
            anyAttached = true;
        }
    }
    if (anyAttached == false) {
        subqueryRSS = null;
    }
    // Get the info on all of the materialized subqueries (attachment point = -1)
    return new RunTimeStatisticsImpl(preStmt.getSPSName(), activation.getCursorName(), preStmt.getSource(), preStmt.getCompileTimeInMillis(), preStmt.getParseTimeInMillis(), preStmt.getBindTimeInMillis(), preStmt.getOptimizeTimeInMillis(), preStmt.getGenerateTimeInMillis(), rs.getExecuteTime(), preStmt.getBeginCompileTimestamp(), preStmt.getEndCompileTimestamp(), rs.getBeginExecutionTimestamp(), rs.getEndExecutionTimestamp(), subqueryRSS, topResultSetStatistics);
}
Also used : ResultSetStatistics(org.apache.derby.iapi.sql.execute.ResultSetStatistics) RealUpdateResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealUpdateResultSetStatistics) RealDeleteResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealDeleteResultSetStatistics) RealDeleteVTIResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealDeleteVTIResultSetStatistics) RealAnyResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealAnyResultSetStatistics) RealScrollInsensitiveResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealScrollInsensitiveResultSetStatistics) RealRowResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealRowResultSetStatistics) RealMaterializedResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealMaterializedResultSetStatistics) RealNormalizeResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealNormalizeResultSetStatistics) RealUnionResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealUnionResultSetStatistics) RealOnceResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealOnceResultSetStatistics) RealInsertResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealInsertResultSetStatistics) RealJoinResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealJoinResultSetStatistics) RealWindowResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealWindowResultSetStatistics) RealSetOpResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealSetOpResultSetStatistics) RealInsertVTIResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealInsertVTIResultSetStatistics) RealDeleteCascadeResultSetStatistics(org.apache.derby.impl.sql.execute.rts.RealDeleteCascadeResultSetStatistics) NoPutResultSet(org.apache.derby.iapi.sql.execute.NoPutResultSet) PreparedStatement(org.apache.derby.iapi.sql.PreparedStatement) RunTimeStatisticsImpl(org.apache.derby.impl.sql.execute.rts.RunTimeStatisticsImpl)

Example 5 with NoPutResultSet

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

the class ScrollInsensitiveResultSet method getRowFromHashTable.

/**
 * Get the row at the specified position
 * from the hash table.
 *
 * @param position	The specified position.
 *
 * @return	The row at that position.
 *
 * @exception StandardException thrown on failure
 */
private ExecRow getRowFromHashTable(int position) throws StandardException {
    // Get the row from the hash table
    positionInHashTable.setValue(position);
    DataValueDescriptor[] hashRowArray = getCurrentRowFromHashtable();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(hashRowArray != null, "hashRowArray expected to be non-null");
    }
    // Copy out the Object[] without the position.
    DataValueDescriptor[] resultRowArray = new DataValueDescriptor[hashRowArray.length - extraColumns];
    System.arraycopy(hashRowArray, extraColumns, resultRowArray, 0, resultRowArray.length);
    resultRow.setRowArray(resultRowArray);
    // Reset the current position to the user position
    currentPosition = position;
    numFromHashTable++;
    if (resultRow != null) {
        beforeFirst = false;
        afterLast = false;
    }
    if (isForUpdate()) {
        RowLocation rowLoc = (RowLocation) hashRowArray[POS_ROWLOCATION];
        // Keep source and target with the same currentRow
        ((NoPutResultSet) target).setCurrentRow(resultRow);
        ((NoPutResultSet) target).positionScanAtRowLocation(rowLoc);
        needsRepositioning = true;
    }
    setCurrentRow(resultRow);
    return resultRow;
}
Also used : NoPutResultSet(org.apache.derby.iapi.sql.execute.NoPutResultSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Aggregations

NoPutResultSet (org.apache.derby.iapi.sql.execute.NoPutResultSet)5 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 RowLocation (org.apache.derby.iapi.types.RowLocation)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PreparedStatement (org.apache.derby.iapi.sql.PreparedStatement)1 CursorResultSet (org.apache.derby.iapi.sql.execute.CursorResultSet)1 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)1 ResultSetStatistics (org.apache.derby.iapi.sql.execute.ResultSetStatistics)1 RealAnyResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealAnyResultSetStatistics)1 RealDeleteCascadeResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealDeleteCascadeResultSetStatistics)1 RealDeleteResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealDeleteResultSetStatistics)1 RealDeleteVTIResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealDeleteVTIResultSetStatistics)1 RealInsertResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealInsertResultSetStatistics)1 RealInsertVTIResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealInsertVTIResultSetStatistics)1 RealJoinResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealJoinResultSetStatistics)1 RealMaterializedResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealMaterializedResultSetStatistics)1 RealNormalizeResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealNormalizeResultSetStatistics)1 RealOnceResultSetStatistics (org.apache.derby.impl.sql.execute.rts.RealOnceResultSetStatistics)1