Search in sources :

Example 96 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.

the class GroupedAggregateResultSet method loadSorter.

/**
 * Load up the sorter.  Feed it every row from the
 * source scan.  When done, close
 * the source scan and open the sort.  Return the sort
 * scan controller.
 *
 * @exception StandardException thrown on failure.
 *
 * @return	the sort controller
 */
private ScanController loadSorter() throws StandardException {
    SortController sorter;
    ExecRow inputRow;
    int inputRowCountEstimate = (int) optimizerEstimatedRowCount;
    ExecIndexRow sortTemplateRow = getRowTemplate();
    tc = getTransactionController();
    SortObserver observer;
    if (usingAggregateObserver)
        observer = new AggregateSortObserver(true, aggregates, aggregates, sortTemplateRow);
    else
        observer = new BasicSortObserver(true, false, sortTemplateRow, true);
    genericSortId = tc.createSort((Properties) null, sortTemplateRow.getRowArray(), order, observer, false, // est rows
    inputRowCountEstimate, // est rowsize
    maxRowSize);
    sorter = tc.openSort(genericSortId);
    /* The sorter is responsible for doing the cloning */
    while ((inputRow = getNextRowFromRS()) != null) {
        sorter.insert(inputRow.getRowArray());
    }
    source.close();
    sorter.completedInserts();
    sortProperties = sorter.getSortInfo().getAllSortInfo(sortProperties);
    if (aggInfoList.hasDistinct()) {
        /*
			** If there was a distinct aggregate, then that column
			** was automatically included as the last column in
			** the sort ordering. But we don't want it to be part
			** of the ordering anymore, because we aren't grouping
			** by that column, we just sorted it so that distinct
			** aggregation would see the values in order.
			*/
        // Although it seems like N aggs could have been
        // added at the end, in fact only one has been
        // FIXME -- need to get GroupByNode to handle this
        // correctly, but that requires understanding
        // scalar distinct aggregates.
        numDistinctAggs = 1;
    }
    return tc.openSortScan(genericSortId, activation.getResultSetHoldability());
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) Properties(java.util.Properties) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SortObserver(org.apache.derby.iapi.store.access.SortObserver) SortController(org.apache.derby.iapi.store.access.SortController)

Example 97 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.

the class HashScanResultSet method getNextRowCore.

/**
 * Return the next row (if any) from the scan (if open).
 *
 * @exception StandardException thrown on failure to get next row
 */
public ExecRow getNextRowCore() throws StandardException {
    if (isXplainOnlyMode())
        return null;
    ExecRow result = null;
    DataValueDescriptor[] columns = null;
    beginTime = getCurrentTimeMillis();
    if (isOpen && hashtableBuilt) {
        /* 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 = hashtable.get(nextQualifiers[0][0].getOrderable());
                } else {
                    KeyHasher mh = new KeyHasher(keyColumns.length);
                    if (SanityManager.DEBUG) {
                        SanityManager.ASSERT(nextQualifiers.length == 1);
                    }
                    for (int index = 0; index < keyColumns.length; index++) {
                        // For hashing only use the AND qualifiers
                        // located in nextQualifiers[0][0...N], OR
                        // qualifiers are checked down a bit by calling
                        // qualifyRow on rows returned from hash.
                        DataValueDescriptor dvd = nextQualifiers[0][index].getOrderable();
                        if (dvd == null) {
                            mh = null;
                            break;
                        }
                        mh.setObject(index, nextQualifiers[0][index].getOrderable());
                    }
                    hashEntry = (mh == null) ? null : hashtable.get(mh);
                }
                if (hashEntry instanceof List) {
                    entryVector = (List) hashEntry;
                    entryVectorSize = entryVector.size();
                    columns = unpackHashValue(entryVector.get(0));
                } else {
                    entryVector = null;
                    entryVectorSize = 0;
                    columns = unpackHashValue(hashEntry);
                }
            } else if (numFetchedOnNext < entryVectorSize) {
                // We are walking a list and there are more rows left.
                columns = unpackHashValue(entryVector.get(numFetchedOnNext));
            }
            if (columns != null) {
                if (RowUtil.qualifyRow(columns, nextQualifiers)) {
                    setCompatRow(compactRow, columns);
                    rowsSeen++;
                    result = compactRow;
                } else {
                    result = null;
                }
                numFetchedOnNext++;
            } else {
                result = null;
            }
        } while (result == null && numFetchedOnNext < entryVectorSize);
    }
    setCurrentRow(result);
    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) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 98 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.

the class HashTableResultSet 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) {
        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) {
            result.setColumn(index + 1, sourceRow.getColumn(projectMapping[index]));
        }
    }
    /* 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)

Example 99 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.

the class HashTableResultSet method getNextRowFromRowSource.

// RowSource interface
/**
 * @see RowSource#getNextRowFromRowSource
 * @exception StandardException on error
 */
public DataValueDescriptor[] getNextRowFromRowSource() throws StandardException {
    ExecRow execRow = source.getNextRowCore();
    /* Use the single table predicates, if any,
		 * to filter out rows while populating the
		 * hash table.
		 */
    while (execRow != null) {
        boolean restrict = false;
        DataValueDescriptor restrictBoolean;
        rowsSeen++;
        /* 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 (!restrict) {
            execRow = source.getNextRowCore();
            continue;
        }
        if (targetResultSet != null) {
            /* Let the target preprocess the row.  For now, this
				 * means doing an in place clone on any indexed columns
				 * to optimize cloning and so that we don't try to drain
				 * a stream multiple times.  This is where we also
				 * enforce any check constraints.
				 */
            clonedExecRow = targetResultSet.preprocessSourceRow(execRow);
        }
        /* Get a single ExecRow of the same size
			 * on the way in so that we have a row
			 * to use on the way out.
			 */
        if (firstIntoHashtable) {
            nextCandidate = activation.getExecutionFactory().getValueRow(execRow.nColumns());
            firstIntoHashtable = false;
        }
        return execRow.getRowArray();
    }
    return null;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 100 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow in project derby by apache.

the class ResultColumnList method buildEmptyIndexRow.

/**
 *	Build an empty index row for the given conglomerate.
 *
 *	@return	an empty row of the correct size and shape.
 * @exception StandardException		Thrown on error
 */
public ExecRow buildEmptyIndexRow(TableDescriptor td, ConglomerateDescriptor cd, StoreCostController scc, DataDictionary dd) throws StandardException {
    ResultColumn rc;
    if (SanityManager.DEBUG) {
        if (!cd.isIndex()) {
            SanityManager.THROWASSERT("ConglomerateDescriptor expected to be for index: " + cd);
        }
    }
    int[] baseCols = cd.getIndexDescriptor().baseColumnPositions();
    ExecRow row = getExecutionFactory().getValueRow(baseCols.length + 1);
    for (int i = 0; i < baseCols.length; i++) {
        ColumnDescriptor coldes = td.getColumnDescriptor(baseCols[i]);
        DataTypeDescriptor dataType = coldes.getType();
        // rc = getResultColumn(baseCols[i]);
        // rc = (ResultColumn) at(baseCols[i] - 1);
        // dataType = rc.getTypeServices();
        DataValueDescriptor dataValue = dataType.getNull();
        row.setColumn(i + 1, dataValue);
    }
    RowLocation rlTemplate = scc.newRowLocationTemplate();
    row.setColumn(baseCols.length + 1, rlTemplate);
    return row;
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

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