ExternalSortOutput Class Reference

ExternalSortMerger marshals XO output buffers by fetching from a top-level ExternalSortSubStream. More...

#include <ExternalSortOutput.h>

List of all members.

Public Member Functions

 ExternalSortOutput (ExternalSortInfo &info)
virtual ~ExternalSortOutput ()
void setSubStream (ExternalSortSubStream &subStream)
 Sets the substream from which to fetch.
ExecStreamResult fetch (ExecStreamBufAccessor &bufAccessor)
 Fetches tuples and writes them to a buffer.
void releaseResources ()
 Releases any resources acquired by this object.

Private Attributes

ExternalSortInfosortInfo
 Global information.
TupleAccessor tupleAccessor
ExternalSortSubStreampSubStream
 Substream from which to fetch.
ExternalSortFetchArraypFetchArray
 Fetch array bound to substream.
uint iCurrentTuple
 0-based index of next tuple to return from fetch array.


Detailed Description

ExternalSortMerger marshals XO output buffers by fetching from a top-level ExternalSortSubStream.

Definition at line 39 of file ExternalSortOutput.h.


Constructor & Destructor Documentation

ExternalSortOutput::ExternalSortOutput ( ExternalSortInfo info  )  [explicit]

Definition at line 32 of file ExternalSortOutput.cpp.

References TupleAccessor::compute(), iCurrentTuple, pFetchArray, pSubStream, sortInfo, tupleAccessor, and ExternalSortInfo::tupleDesc.

00033     : sortInfo(sortInfoIn)
00034 {
00035     pSubStream = NULL;
00036     pFetchArray = NULL;
00037     iCurrentTuple = 0;
00038 
00039     tupleAccessor.compute(sortInfo.tupleDesc);
00040 }

ExternalSortOutput::~ExternalSortOutput (  )  [virtual]

Definition at line 42 of file ExternalSortOutput.cpp.

References releaseResources().

00043 {
00044     releaseResources();
00045 }


Member Function Documentation

void ExternalSortOutput::setSubStream ( ExternalSortSubStream subStream  ) 

Sets the substream from which to fetch.

Parameters:
subStream new source

Definition at line 51 of file ExternalSortOutput.cpp.

References ExternalSortSubStream::bindFetchArray(), iCurrentTuple, pFetchArray, and pSubStream.

00052 {
00053     iCurrentTuple = 0;
00054 
00055     pSubStream = &subStream;
00056     pFetchArray = &(subStream.bindFetchArray());
00057 }

ExecStreamResult ExternalSortOutput::fetch ( ExecStreamBufAccessor bufAccessor  ) 

Fetches tuples and writes them to a buffer.

Parameters:
bufAccessor receives marshalled tuple data
Returns:
result

Definition at line 59 of file ExternalSortOutput.cpp.

References EXECRC_BUF_OVERFLOW, EXTSORT_ENDOFDATA, EXTSORT_FETCH_ARRAY_SIZE, ExternalSortSubStream::fetch(), TupleAccessor::getBufferByteCount(), ExecStreamBufAccessor::getProductionAvailable(), ExecStreamBufAccessor::getProductionStart(), iCurrentTuple, ExternalSortFetchArray::nTuples, pFetchArray, ExternalSortFetchArray::ppTupleBuffers, pSubStream, ExecStreamBufAccessor::requestConsumption(), and tupleAccessor.

00061 {
00062     uint cbRemaining = bufAccessor.getProductionAvailable();
00063     PBuffer pOutBuf = bufAccessor.getProductionStart();
00064     PBuffer pNextTuple = pOutBuf;
00065 
00066     for (;;) {
00067         if (iCurrentTuple >= pFetchArray->nTuples) {
00068             ExternalSortRC rc = pSubStream->fetch(EXTSORT_FETCH_ARRAY_SIZE);
00069             if (rc == EXTSORT_ENDOFDATA) {
00070                 goto done;
00071             }
00072             iCurrentTuple = 0;
00073         }
00074 
00075         while (iCurrentTuple < pFetchArray->nTuples) {
00076             PConstBuffer pSrcTuple =
00077                 pFetchArray->ppTupleBuffers[iCurrentTuple];
00078             uint cbTuple = tupleAccessor.getBufferByteCount(pSrcTuple);
00079             if (cbTuple > cbRemaining) {
00080                 if (pNextTuple == pOutBuf) {
00081                     bufAccessor.requestConsumption();
00082                     return EXECRC_BUF_OVERFLOW;
00083                 }
00084                 goto done;
00085             }
00086             memcpy(pNextTuple,pSrcTuple,cbTuple);
00087             cbRemaining -= cbTuple;
00088             pNextTuple += cbTuple;
00089             iCurrentTuple++;
00090         }
00091     }
00092 
00093  done:
00094     if (pNextTuple == pOutBuf) {
00095         bufAccessor.markEOS();
00096         return EXECRC_EOS;
00097     } else {
00098         bufAccessor.produceData(pNextTuple);
00099         bufAccessor.requestConsumption();
00100         // REVIEW:  sometimes should be EXECRC_EOS instead
00101         return EXECRC_BUF_OVERFLOW;
00102     }
00103 }

void ExternalSortOutput::releaseResources (  ) 

Releases any resources acquired by this object.

Definition at line 47 of file ExternalSortOutput.cpp.

Referenced by ~ExternalSortOutput().

00048 {
00049 }


Member Data Documentation

ExternalSortInfo& ExternalSortOutput::sortInfo [private]

Global information.

Definition at line 44 of file ExternalSortOutput.h.

Referenced by ExternalSortOutput().

TupleAccessor ExternalSortOutput::tupleAccessor [private]

Definition at line 47 of file ExternalSortOutput.h.

Referenced by ExternalSortOutput(), and fetch().

ExternalSortSubStream* ExternalSortOutput::pSubStream [private]

Substream from which to fetch.

Definition at line 52 of file ExternalSortOutput.h.

Referenced by ExternalSortOutput(), fetch(), and setSubStream().

ExternalSortFetchArray* ExternalSortOutput::pFetchArray [private]

Fetch array bound to substream.

Definition at line 57 of file ExternalSortOutput.h.

Referenced by ExternalSortOutput(), fetch(), and setSubStream().

uint ExternalSortOutput::iCurrentTuple [private]

0-based index of next tuple to return from fetch array.

Definition at line 62 of file ExternalSortOutput.h.

Referenced by ExternalSortOutput(), fetch(), and setSubStream().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:32 2009 for Fennel by  doxygen 1.5.1