Search in sources :

Example 86 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class BaseExpressionActivation method maxValue.

/**
 * <p>
 * Get the maximum value of 4 input values.  If less than 4 values, input
 * {@code null} for the unused parameters and place them at the end.
 * If more than 4 input values, call this multiple times to
 * accumulate results.  Also have judge's type as parameter to have a base
 * upon which the comparison is based.  An example use is for code
 * generation in bug 3858.
 * </p>
 *
 * <p>
 * If all the input values are SQL NULL, return SQL NULL. Otherwise, return
 * the maximum value of the non-NULL inputs.
 * </p>
 *
 * @param v1		1st value
 * @param v2		2nd value
 * @param v3		3rd value
 * @param v4		4th value
 * @param judgeTypeFormatId		type format id of the judge
 * @param judgeUserJDBCTypeId	JDBC type id if judge is user type;
 *								-1 if not user type
 *
 * @return	The maximum value of the 4.
 */
public static DataValueDescriptor maxValue(DataValueDescriptor v1, DataValueDescriptor v2, DataValueDescriptor v3, DataValueDescriptor v4, int judgeTypeFormatId, int judgeUserJDBCTypeId, int judgePrecision, int judgeScale, boolean judgeIsNullable, int judgeMaximumWidth, int judgeCollationType, int judgeCollationDerivation) throws StandardException {
    DataValueDescriptor judge;
    if (judgeUserJDBCTypeId == -1) {
        judge = new DataTypeDescriptor(new TypeId(judgeTypeFormatId, null), judgePrecision, judgeScale, judgeIsNullable, judgeMaximumWidth, judgeCollationType, judgeCollationDerivation).getNull();
    } else
        judge = new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();
    DataValueDescriptor maxVal = v1;
    if (v2 != null && (maxVal.isNull() || judge.greaterThan(v2, maxVal).equals(true)))
        maxVal = v2;
    if (v3 != null && (maxVal.isNull() || judge.greaterThan(v3, maxVal).equals(true)))
        maxVal = v3;
    if (v4 != null && (maxVal.isNull() || judge.greaterThan(v4, maxVal).equals(true)))
        maxVal = v4;
    return maxVal;
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) UserDefinedTypeIdImpl(org.apache.derby.catalog.types.UserDefinedTypeIdImpl) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 87 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class ValueNodeList method sortInAscendingOrder.

/**
 * Sort the entries in the list in ascending order.
 * (All values are assumed to be constants.)
 *
 * @param judgeODV  In case of type not exactly matching, the judging type.
 *
 * @exception StandardException		Thrown on error
 */
void sortInAscendingOrder(DataValueDescriptor judgeODV) throws StandardException {
    int size = size();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(size > 0, "size() expected to be non-zero");
    }
    /* We use bubble sort to sort the list since we expect
		 * the list to be in sorted order > 90% of the time.
		 */
    boolean continueSort = true;
    while (continueSort) {
        continueSort = false;
        for (int index = 1; index < size; index++) {
            ConstantNode currCN = (ConstantNode) elementAt(index);
            DataValueDescriptor currODV = currCN.getValue();
            ConstantNode prevCN = (ConstantNode) elementAt(index - 1);
            DataValueDescriptor prevODV = prevCN.getValue();
            /* Swap curr and prev if prev > curr */
            if ((judgeODV == null && (prevODV.compare(currODV)) > 0) || (judgeODV != null && judgeODV.greaterThan(prevODV, currODV).equals(true))) {
                setElementAt(currCN, index - 1);
                setElementAt(prevCN, index);
                continueSort = true;
            }
        }
    }
}
Also used : DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 88 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class ProjectRestrictResultSet 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) ((restriction == null) ? null : restriction.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 89 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class ProjectRestrictResultSet method reopenCore.

/**
 * reopen a scan on the table. scan parameters are evaluated
 * at each open, so there is probably some way of altering
 * their values...
 *
 * @exception StandardException thrown if cursor finished.
 */
public void reopenCore() throws StandardException {
    boolean constantEval = true;
    beginTime = getCurrentTimeMillis();
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(isOpen, "ProjectRestrictResultSet not open, cannot reopen");
    if (constantRestriction != null) {
        DataValueDescriptor restrictBoolean;
        restrictBoolean = (DataValueDescriptor) constantRestriction.invoke(activation);
        // if the result is null, we make it false --
        // so the row won't be returned.
        constantEval = (restrictBoolean == null) || ((!restrictBoolean.isNull()) && restrictBoolean.getBoolean());
    }
    if (constantEval) {
        source.reopenCore();
    } else {
        shortCircuitOpen = true;
    }
    isOpen = true;
    numOpens++;
    openTime += getElapsedMillis(beginTime);
}
Also used : DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 90 with DataValueDescriptor

use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.

the class ProjectRestrictResultSet method doProjection.

/**
 * Do the projection against the source row.  Use reflection
 * where necessary, otherwise get the source column into our
 * result row.
 *
 * @param sourceRow		The source row.
 *
 * @return		The result of the projection
 *
 * @exception StandardException thrown on failure.
 */
private ExecRow doProjection(ExecRow sourceRow) throws StandardException {
    // No need to use reflection if reusing the result
    if (reuseResult && projRow != null) {
        /* Make sure we reset the current row based on the re-used
			 * result.  Otherwise, if the "current row" for this result
			 * set was nulled out in a previous call to getNextRow(),
			 * which can happen if this node is the right-side of
			 * a left outer join, the "current row" stored for this
			 * result set in activation.row would remain null, which
			 * would be wrong. DERBY-3538.
			 */
        setCurrentRow(projRow);
        return projRow;
    }
    ExecRow result;
    // Use reflection to do as much of projection as required
    if (projection != null) {
        result = (ExecRow) projection.invoke(activation);
    } else {
        result = mappedResultRow;
    }
    // Copy any mapped columns from the source
    for (int index = 0; index < projectMapping.length; index++) {
        if (projectMapping[index] != -1) {
            DataValueDescriptor dvd = sourceRow.getColumn(projectMapping[index]);
            // If the value isn't a stream, don't bother cloning it.
            if (cloneMap[index] && dvd.hasStream()) {
                dvd = dvd.cloneValue(false);
            }
            result.setColumn(index + 1, dvd);
        }
    }
    /* We need to reSet the current row after doing the projection */
    setCurrentRow(result);
    /* Remember the result if reusing it */
    if (reuseResult) {
        projRow = result;
    }
    return result;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Aggregations

DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)328 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)72 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)62 RowLocation (org.apache.derby.iapi.types.RowLocation)54 SQLLongint (org.apache.derby.iapi.types.SQLLongint)51 StandardException (org.apache.derby.shared.common.error.StandardException)43 SQLChar (org.apache.derby.iapi.types.SQLChar)42 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)36 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)36 ScanController (org.apache.derby.iapi.store.access.ScanController)35 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)32 UUID (org.apache.derby.catalog.UUID)31 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)24 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)16 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)15 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)15 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)15 Properties (java.util.Properties)14 UserType (org.apache.derby.iapi.types.UserType)13 Page (org.apache.derby.iapi.store.raw.Page)11