use of org.apache.derby.iapi.types.DataValueDescriptor 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.types.DataValueDescriptor in project derby by apache.
the class GroupedAggregateResultSet method initializeDistinctMaps.
private void initializeDistinctMaps(int r, boolean allocate) throws StandardException {
for (int a = 0; a < aggregates.length; a++) {
AggregatorInfo aInfo = aggInfoList.elementAt(a);
if (allocate) {
// Allocate an empty set if the aggregate is distinct.
// Otherwise, insert null so that the list is of the right
// size and the indexes match those in aggregates[].
distinctValues.get(r).add(aInfo.isDistinct() ? new HashSet<DataValueDescriptor>() : null);
}
if (aInfo.isDistinct()) {
Set<DataValueDescriptor> set = distinctValues.get(r).get(a);
set.clear();
DataValueDescriptor newValue = aggregates[a].getInputColumnValue(resultRows[r]);
set.add(newValue);
}
}
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class HashTableResultSet method getNextRowCore.
/**
* Return the requested values computed
* from the next row (if any) for which
* the restriction evaluates to true.
* <p>
* restriction and projection parameters
* are evaluated for each 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;
ExecRow result = null;
DataValueDescriptor[] columns = null;
beginTime = getCurrentTimeMillis();
if (isOpen) {
/* We use a do/while loop to ensure that we continue down
* the duplicate chain, if one exists, until we find a
* row that matches on all probe predicates (or the
* duplicate chain is exhausted.)
*/
do {
if (firstNext) {
firstNext = false;
/* Hash key could be either a single column or multiple
* columns. If a single column, then it is the datavalue
* wrapper, otherwise it is a KeyHasher.
*/
Object hashEntry;
if (keyColumns.length == 1) {
hashEntry = ht.get(nextQualifiers[0][0].getOrderable());
} else {
KeyHasher mh = new KeyHasher(keyColumns.length);
for (int index = 0; index < keyColumns.length; index++) {
// RESOLVE (mikem) - will need to change when we
// support OR's in qualifiers.
mh.setObject(index, nextQualifiers[0][index].getOrderable());
}
hashEntry = ht.get(mh);
}
if (hashEntry instanceof List) {
entryVector = (List) hashEntry;
entryVectorSize = entryVector.size();
columns = (DataValueDescriptor[]) entryVector.get(0);
} else {
entryVector = null;
entryVectorSize = 0;
columns = (DataValueDescriptor[]) hashEntry;
}
} else if (numFetchedOnNext < entryVectorSize) {
// We are walking a list and there are more rows left.
columns = (DataValueDescriptor[]) entryVector.get(numFetchedOnNext);
}
if (columns != null) {
if (SanityManager.DEBUG) {
// Columns is really a Storable[]
for (int i = 0; i < columns.length; i++) {
if (!(columns[i] instanceof Storable)) {
SanityManager.THROWASSERT("columns[" + i + "] expected to be Storable, not " + columns[i].getClass().getName());
}
}
}
// See if the entry satisfies all of the other qualifiers
boolean qualifies = true;
if (SanityManager.DEBUG) {
// we don't support 2 d qualifiers yet.
SanityManager.ASSERT(nextQualifiers.length == 1);
}
for (int index = 0; index < nextQualifiers[0].length; index++) {
Qualifier q = nextQualifiers[0][index];
qualifies = columns[q.getColumnId()].compare(q.getOperator(), q.getOrderable(), q.getOrderedNulls(), q.getUnknownRV());
if (q.negateCompareResult()) {
qualifies = !(qualifies);
}
// Stop if any predicate fails
if (!qualifies) {
break;
}
}
if (qualifies) {
for (int index = 0; index < columns.length; index++) {
nextCandidate.setColumn(index + 1, columns[index]);
}
result = doProjection(nextCandidate);
} else {
result = null;
}
numFetchedOnNext++;
} else {
result = null;
}
} while (result == null && numFetchedOnNext < entryVectorSize);
}
setCurrentRow(result);
nextTime += getElapsedMillis(beginTime);
if (runTimeStatsOn) {
if (!isTopResultSet) {
/* This is simply for RunTimeStats */
/* We first need to get the subquery tracking array via the StatementContext */
StatementContext sc = activation.getLanguageConnectionContext().getStatementContext();
subqueryTrackingArray = sc.getSubqueryTrackingArray();
}
nextTime += getElapsedMillis(beginTime);
}
return result;
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class HashTableResultSet method getCurrentRow.
/**
* Gets last row returned.
*
* @see CursorResultSet
*
* @return the last row returned.
* @exception StandardException thrown on failure.
*/
/* RESOLVE - this should return activation.getCurrentRow(resultSetNumber),
* once there is such a method. (currentRow is redundant)
*/
public ExecRow getCurrentRow() throws StandardException {
ExecRow candidateRow = null;
ExecRow result = null;
boolean restrict = false;
DataValueDescriptor restrictBoolean;
if (SanityManager.DEBUG)
SanityManager.ASSERT(isOpen, "PRRS is expected to be open");
/* Nothing to do if we're not currently on a row */
if (currentRow == null) {
return null;
}
/* Call the child result set to get it's current row.
* If no row exists, then return null, else requalify it
* before returning.
*/
candidateRow = ((CursorResultSet) source).getCurrentRow();
if (candidateRow != null) {
setCurrentRow(candidateRow);
/* If restriction is null, then all rows qualify */
restrictBoolean = (DataValueDescriptor) ((singleTableRestriction == null) ? null : singleTableRestriction.invoke(activation));
// if the result is null, we make it false --
// so the row won't be returned.
restrict = (restrictBoolean == null) || ((!restrictBoolean.isNull()) && restrictBoolean.getBoolean());
}
if (candidateRow != null && restrict) {
result = doProjection(candidateRow);
}
currentRow = result;
/* Clear the current row, if null */
if (result == null) {
clearCurrentRow();
}
return currentRow;
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class IndexChanger method indexRowChanged.
/**
* Determine whether or not any columns in the current index
* row are being changed by the update. No need to update the
* index if no columns changed.
*
* @return Nothing.
*
* @exception StandardException Thrown on error
*/
private boolean indexRowChanged() throws StandardException {
int numColumns = ourIndexRow.nColumns();
for (int index = 1; index <= numColumns; index++) {
DataValueDescriptor oldOrderable = ourIndexRow.getColumn(index);
DataValueDescriptor newOrderable = ourUpdatedIndexRow.getColumn(index);
if (!(oldOrderable.compare(DataValueDescriptor.ORDER_OP_EQUALS, newOrderable, true, true))) {
return true;
}
}
return false;
}
Aggregations