Search in sources :

Example 51 with ExecRow

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;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 52 with ExecRow

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;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 53 with ExecRow

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;
}
Also used : KeyHasher(org.apache.derby.iapi.store.access.KeyHasher) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) List(java.util.List) Qualifier(org.apache.derby.iapi.store.access.Qualifier) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) Storable(org.apache.derby.iapi.services.io.Storable) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Example 54 with ExecRow

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;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 55 with ExecRow

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;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Aggregations

ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)155 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)62 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)34 RowLocation (org.apache.derby.iapi.types.RowLocation)27 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)23 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)22 ScanController (org.apache.derby.iapi.store.access.ScanController)22 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)22 SQLChar (org.apache.derby.iapi.types.SQLChar)21 SQLLongint (org.apache.derby.iapi.types.SQLLongint)21 UUID (org.apache.derby.catalog.UUID)19 Properties (java.util.Properties)12 TransactionController (org.apache.derby.iapi.store.access.TransactionController)12 CursorResultSet (org.apache.derby.iapi.sql.execute.CursorResultSet)11 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)10 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)10 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)10 UserType (org.apache.derby.iapi.types.UserType)9 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)8 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)7