LhxHashTableReader Class Reference

#include <LhxHashTable.h>

List of all members.

Public Member Functions

void init (LhxHashTable *hashTableInit, LhxHashInfo const &hashInfo, uint buildInputIndex)
 Initialize the hash table reader.
void bindKey (PBuffer key)
 Bind this reader to a certain key.
void bindUnMatched ()
 Bind this reader to unmatched keys.
bool getNext (TupleData &outputTuple)
 Get the next outputTuple.
LhxHashTablegetHashTable ()

Private Member Functions

bool advanceSlot ()
 Locate the next slot to produce tuples from.
bool advanceKey ()
 Locate the next key to produce tuples from.
bool advanceData ()
 Locate the next data to produce tuples from.
void produceTuple (TupleData &outputTuple)
 Produce the curKey + curData into outputTuple.
void bind (PBuffer key)
 Helper function for bindKey() and bindUnMatched().

Private Attributes

LhxHashTablehashTable
 Underlying hash table to read from.
bool isGroupBy
 Marks if this hash table is built for aggregation.
PBuffercurSlot
 Current read location.
PBuffer curKey
PBuffer curData
PBuffer boundKey
 If not NULL, only read tuple with matching keys.
bool returnUnMatched
 If true, only return tuples with unmatched keys.
bool isPositioned
 Whether reader is positioned.
LhxHashKeyAccessor hashKeyAccessor
 Accessors for the content of this hash table.
LhxHashDataAccessor hashDataAccessor
TupleProjection keyColsAndAggsProj
 Fields in the outputTuple that will hold keyCols and Aggs, and data columns.
TupleProjection dataProj


Detailed Description

Definition at line 908 of file LhxHashTable.h.


Member Function Documentation

bool LhxHashTableReader::advanceSlot (  )  [private]

Locate the next slot to produce tuples from.

Set up the curKey and curData pointers.

Returns:
false if there is no more slots with keys.

Definition at line 1019 of file LhxHashTable.cpp.

References boundKey, curData, curKey, curSlot, LhxHashKeyAccessor::getFirstData(), LhxHashTable::getFirstSlot(), LhxHashNodeAccessor::getNext(), LhxHashTable::getNextSlot(), hashDataAccessor, hashKeyAccessor, hashTable, isGroupBy, LhxHashKeyAccessor::isMatched(), isPositioned, returnUnMatched, LhxHashDataAccessor::setCurrent(), and LhxHashKeyAccessor::setCurrent().

Referenced by getNext().

01020 {
01021     if (!boundKey) {
01022         curKey = NULL;
01023 
01024         if (!isPositioned) {
01025             curSlot = hashTable->getFirstSlot();
01026         } else {
01027             curSlot = hashTable->getNextSlot(curSlot);
01028         }
01029 
01030         if (curSlot && *curSlot) {
01031             curKey = *curSlot;
01032             if (returnUnMatched) {
01033                 /*
01034                  * Look at all the keys in this slot.
01035                  */
01036                 hashKeyAccessor.setCurrent(*curSlot, true);
01037 
01038                 /*
01039                  * Only return unmatched keys
01040                  */
01041                 while (hashKeyAccessor.isMatched()) {
01042                     curKey = hashKeyAccessor.getNext();
01043                     if (!curKey) {
01044                         curSlot = hashTable->getNextSlot(curSlot);
01045                         if (curSlot) {
01046                             curKey = *curSlot;
01047                         } else {
01048                             curKey = NULL;
01049                         }
01050                     }
01051 
01052                     if (curKey) {
01053                         hashKeyAccessor.setCurrent(curKey, true);
01054                     } else {
01055                         /*
01056                          * Reached the end of the slot list.
01057                          */
01058                         break;
01059                     }
01060                 }
01061             }
01062         }
01063 
01064         if (!curKey) {
01065             /*
01066              * Cound not find any slot with fitting key.
01067              */
01068             return false;
01069         }
01070     }
01071 
01072     hashKeyAccessor.setCurrent(curKey, true);
01073 
01074     if (!isGroupBy) {
01075         curData = hashKeyAccessor.getFirstData();
01076         assert(curData);
01077         hashDataAccessor.setCurrent(curData, true);
01078     }
01079 
01080     return true;
01081 }

bool LhxHashTableReader::advanceKey (  )  [private]

Locate the next key to produce tuples from.

Set up the curKey and curData pointers.

Returns:
false if there is no more keys in the same slot.

Definition at line 1083 of file LhxHashTable.cpp.

References curData, curKey, LhxHashKeyAccessor::getFirstData(), LhxHashNodeAccessor::getNext(), hashDataAccessor, hashKeyAccessor, isGroupBy, LhxHashKeyAccessor::isMatched(), returnUnMatched, LhxHashDataAccessor::setCurrent(), and LhxHashKeyAccessor::setCurrent().

Referenced by getNext().

01084 {
01085     while ((curKey = hashKeyAccessor.getNext())) {
01086         if (!returnUnMatched) {
01087             break;
01088         } else {
01089             hashKeyAccessor.setCurrent(curKey, true);
01090             if (!hashKeyAccessor.isMatched()) {
01091                 break;
01092             }
01093         }
01094     }
01095 
01096     if (curKey) {
01097         hashKeyAccessor.setCurrent(curKey, true);
01098         if (!isGroupBy) {
01099             curData = hashKeyAccessor.getFirstData();
01100             assert(curData);
01101             hashDataAccessor.setCurrent(curData, true);
01102         }
01103         return true;
01104     } else {
01105         return false;
01106     }
01107 }

bool LhxHashTableReader::advanceData (  )  [private]

Locate the next data to produce tuples from.

Set up the curData pointers.

Returns:
false if there is no more data with the same key.

Definition at line 1109 of file LhxHashTable.cpp.

References curData, LhxHashNodeAccessor::getNext(), hashDataAccessor, isGroupBy, and LhxHashDataAccessor::setCurrent().

Referenced by getNext().

01110 {
01111     if (isGroupBy) {
01112         return false;
01113     }
01114 
01115     curData = hashDataAccessor.getNext();
01116     if (curData) {
01117         hashDataAccessor.setCurrent(curData, true);
01118         return true;
01119     } else {
01120         return false;
01121     }
01122 }

void LhxHashTableReader::produceTuple ( TupleData outputTuple  )  [private]

Produce the curKey + curData into outputTuple.

Definition at line 1124 of file LhxHashTable.cpp.

References dataProj, hashDataAccessor, hashKeyAccessor, isGroupBy, keyColsAndAggsProj, LhxHashDataAccessor::unpack(), and LhxHashKeyAccessor::unpack().

Referenced by getNext().

01125 {
01126     hashKeyAccessor.unpack(outputTuple, keyColsAndAggsProj);
01127     if (!isGroupBy) {
01128         hashDataAccessor.unpack(outputTuple, dataProj);
01129     }
01130 }

void LhxHashTableReader::bind ( PBuffer  key  )  [inline, private]

Helper function for bindKey() and bindUnMatched().

Definition at line 1313 of file LhxHashTable.h.

References boundKey, curData, curKey, curSlot, and isPositioned.

Referenced by bindKey(), and bindUnMatched().

01314 {
01315     boundKey = curKey = key;
01316     curSlot = NULL;
01317     curData = NULL;
01318     isPositioned = false;
01319 }

void LhxHashTableReader::init ( LhxHashTable hashTableInit,
LhxHashInfo const &  hashInfo,
uint  buildInputIndex 
)

Initialize the hash table reader.

Parameters:
[in] hashTableInit the underlying hash table to read from
[in] hashInfo 
[in] buildInputIndex which input is the build side.

Definition at line 1132 of file LhxHashTable.cpp.

References LhxHashInfo::aggsProj, bindKey(), LhxHashInfo::dataProj, dataProj, hashDataAccessor, hashKeyAccessor, hashTable, LhxHashDataAccessor::init(), LhxHashKeyAccessor::init(), LhxHashInfo::inputDesc, isGroupBy, LhxHashTable::isHashGroupBy(), keyColsAndAggsProj, and LhxHashInfo::keyProj.

Referenced by LhxJoinExecStream::execute(), LhxAggExecStream::execute(), LhxPartitionWriter::open(), LhxJoinExecStream::open(), LhxAggExecStream::open(), LhxHashTableTest::testInsert(), and LhxHashTableTest::writeHashTable().

01136 {
01137     /*
01138      * The last input is the build side.
01139      */
01140     TupleDescriptor const &outputTupleDesc =
01141         hashInfo.inputDesc[buildInputIndex];
01142     TupleProjection const &keyColsProj = hashInfo.keyProj[buildInputIndex];
01143     TupleProjection const &aggsProj = hashInfo.aggsProj;
01144 
01145     dataProj = hashInfo.dataProj[buildInputIndex];
01146 
01147     /*
01148      * These steps initialize the keyColsProjInKey and aggsProjInKey which are
01149      * based on the new keyColsAndAggs tuple.
01150      */
01151     TupleDescriptor keyDesc;
01152     TupleDescriptor dataDesc;
01153     TupleProjection keyColsProjInKey;
01154     TupleProjection aggsProjInKey;
01155     uint keyCount = keyColsProj.size();
01156     uint i;
01157 
01158     for (i = 0; i < keyCount; i++) {
01159         keyDesc.push_back(outputTupleDesc[keyColsProj[i]]);
01160         keyColsProjInKey.push_back(i);
01161     }
01162 
01163     keyColsAndAggsProj = keyColsProj;
01164     uint aggsProjSize = aggsProj.size();
01165 
01166     for (i = 0; i < aggsProjSize; i ++) {
01167         keyColsAndAggsProj.push_back(aggsProj[i]);
01168         keyDesc.push_back(outputTupleDesc[aggsProj[i]]);
01169         aggsProjInKey.push_back(i + keyCount);
01170     }
01171 
01172     hashKeyAccessor.init(keyDesc, keyColsProjInKey, aggsProjInKey);
01173 
01174     for (i = 0; i < dataProj.size(); i++) {
01175         dataDesc.push_back(outputTupleDesc[dataProj[i]]);
01176     }
01177 
01178     hashDataAccessor.init(dataDesc);
01179 
01180     hashTable = hashTableInit;
01181     isGroupBy = hashTable->isHashGroupBy();
01182 
01183     /*
01184      * By default, this reader is not associated with any key, i.e. it covers
01185      * the whole hash table.
01186      */
01187     bindKey(NULL);
01188 }

void LhxHashTableReader::bindKey ( PBuffer  key  )  [inline]

Bind this reader to a certain key.

Only tuples with the same key are returned.

Parameters:
[in] key key node to bind this reader to.

Definition at line 1321 of file LhxHashTable.h.

References bind(), and returnUnMatched.

Referenced by LhxPartitionWriter::aggAndMarshalTuple(), LhxJoinExecStream::execute(), init(), LhxPartitionInfo::open(), LhxHashTableTest::testInsert(), and LhxHashTableTest::writeHashTable().

01322 {
01323     returnUnMatched = false;
01324     bind(key);
01325 }

void LhxHashTableReader::bindUnMatched (  )  [inline]

Bind this reader to unmatched keys.

Only rows with unmatched keys will be returned.

Definition at line 1327 of file LhxHashTable.h.

References bind(), and returnUnMatched.

Referenced by LhxJoinExecStream::execute().

01328 {
01329     returnUnMatched = true;
01330     bind(NULL);
01331 }

bool LhxHashTableReader::getNext ( TupleData outputTuple  ) 

Get the next outputTuple.

Parameters:
[out] outputTuple 
Returns:
false if no more tuples to output.

Definition at line 1190 of file LhxHashTable.cpp.

References advanceData(), advanceKey(), advanceSlot(), boundKey, isPositioned, produceTuple(), and returnUnMatched.

Referenced by LhxPartitionWriter::aggAndMarshalTuple(), LhxPartitionWriter::close(), LhxJoinExecStream::execute(), LhxAggExecStream::execute(), LhxHashTableTest::testInsert(), and LhxHashTableTest::writeHashTable().

01191 {
01192     if (!isPositioned) {
01193         assert (!(boundKey && returnUnMatched));
01194 
01195         /*
01196          * Position at the first qualifying key of the first slot.
01197          */
01198         if (!advanceSlot()) {
01199             /*
01200              * Nothing to output.
01201              */
01202             return false;
01203         }
01204         produceTuple(outputTuple);
01205         isPositioned = true;
01206         return true;
01207     }
01208 
01209     if (advanceData()) {
01210         produceTuple(outputTuple);
01211         return true;
01212     } else {
01213         if (boundKey) {
01214             /*
01215              * End of data for this key.
01216              */
01217             return false;
01218         } else {
01219             /*
01220              * Get the next key in the same slot.
01221              */
01222             if (advanceKey()) {
01223                 produceTuple(outputTuple);
01224                 return true;
01225             } else {
01226                 /*
01227                  * End of list for keys in the same slot..
01228                  * Start the next slot.
01229                  */
01230                 if (advanceSlot()) {
01231                     produceTuple(outputTuple);
01232                     return true;
01233                 } else {
01234                     return false;
01235                 }
01236             }
01237         }
01238     }
01239 }

LhxHashTable * LhxHashTableReader::getHashTable (  )  [inline]

Definition at line 1308 of file LhxHashTable.h.

References hashTable.

01309 {
01310     return hashTable;
01311 }


Member Data Documentation

LhxHashTable* LhxHashTableReader::hashTable [private]

Underlying hash table to read from.

Definition at line 913 of file LhxHashTable.h.

Referenced by advanceSlot(), getHashTable(), and init().

bool LhxHashTableReader::isGroupBy [private]

Marks if this hash table is built for aggregation.

Aggregating hash table only contains keys (group by keys plus aggregates) and does not contain data portion. The reader behavior will thus be different from reading a hash table built for joins.

Definition at line 922 of file LhxHashTable.h.

Referenced by advanceData(), advanceKey(), advanceSlot(), init(), and produceTuple().

PBuffer* LhxHashTableReader::curSlot [private]

Current read location.

Definition at line 927 of file LhxHashTable.h.

Referenced by advanceSlot(), and bind().

PBuffer LhxHashTableReader::curKey [private]

Definition at line 928 of file LhxHashTable.h.

Referenced by advanceKey(), advanceSlot(), and bind().

PBuffer LhxHashTableReader::curData [private]

Definition at line 929 of file LhxHashTable.h.

Referenced by advanceData(), advanceKey(), advanceSlot(), and bind().

PBuffer LhxHashTableReader::boundKey [private]

If not NULL, only read tuple with matching keys.

Not compatible with returnUnMatched

Definition at line 937 of file LhxHashTable.h.

Referenced by advanceSlot(), bind(), and getNext().

bool LhxHashTableReader::returnUnMatched [private]

If true, only return tuples with unmatched keys.

This is not compatible with boundKey.

Definition at line 943 of file LhxHashTable.h.

Referenced by advanceKey(), advanceSlot(), bindKey(), bindUnMatched(), and getNext().

bool LhxHashTableReader::isPositioned [private]

Whether reader is positioned.

Definition at line 948 of file LhxHashTable.h.

Referenced by advanceSlot(), bind(), and getNext().

LhxHashKeyAccessor LhxHashTableReader::hashKeyAccessor [private]

Accessors for the content of this hash table.

Definition at line 953 of file LhxHashTable.h.

Referenced by advanceKey(), advanceSlot(), init(), and produceTuple().

LhxHashDataAccessor LhxHashTableReader::hashDataAccessor [private]

Definition at line 954 of file LhxHashTable.h.

Referenced by advanceData(), advanceKey(), advanceSlot(), init(), and produceTuple().

TupleProjection LhxHashTableReader::keyColsAndAggsProj [private]

Fields in the outputTuple that will hold keyCols and Aggs, and data columns.

output tuple should have the same shape as outputTupleDesc used in the init() method.

Definition at line 963 of file LhxHashTable.h.

Referenced by init(), and produceTuple().

TupleProjection LhxHashTableReader::dataProj [private]

Definition at line 964 of file LhxHashTable.h.

Referenced by init(), and produceTuple().


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