use of org.apache.derby.iapi.sql.execute.ExecRow 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;
}
use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.
the class GroupedAggregateResultSet method makeCurrent.
// Return the passed row, after ensuring that we call setCurrentRow
private ExecRow makeCurrent(Object row) throws StandardException {
ExecRow resultRow = (ExecRow) row;
setCurrentRow(resultRow);
return resultRow;
}
use of org.apache.derby.iapi.sql.execute.ExecRow 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.sql.execute.ExecRow 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.sql.execute.ExecRow in project derby by apache.
the class IndexRowToBaseRowResultSet 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 sourceRow = null;
if (SanityManager.DEBUG) {
SanityManager.ASSERT(isOpen, "IndexRowToBaseRowResultSet is expected to be open");
}
/* Nothing to do if we're not currently on a row */
if (currentRow == null) {
return null;
}
// We do not need to read the row from the index first, since we already
// have the rowLocation of the current row and can read it directly from
// the heap.
sourceRow = activation.getExecutionFactory().getValueRow(indexCols.length);
sourceRow.setRowArray(rowArray);
// Fetch the columns coming from the heap
boolean row_exists = baseCC.fetch(baseRowLocation, rowArray, (FormatableBitSet) null);
if (row_exists) {
setCurrentRow(sourceRow);
} else {
clearCurrentRow();
}
return currentRow;
}
Aggregations