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);
}
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;
}
}
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;
}
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);
}
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;
}
Aggregations