#include <LhxHashTable.h>
Inheritance diagram for LhxHashKeyAccessor:
Public Member Functions | |
LhxHashKeyAccessor () | |
void | init (TupleDescriptor const &keyDescInit, TupleProjection const &keyColsProjInit, TupleProjection const &aggsProjInit) |
Set the shape of the data tuple to be stored via this accessor. | |
void | setCurrent (PBuffer nodePtrInit, bool valid) |
Set the current node pointer for this accessor. | |
PBuffer | getFirstData () |
Get the first data node off this key node. | |
void | setFirstData (PBuffer inputFirstData) |
Set pointer to the first data node. | |
PBuffer * | getNextSlot () |
Get the first data node off this key node. | |
void | setNextSlot (PBuffer *nextSlot) |
Set pointer to the first data node. | |
bool | isMatched () |
Check if this key has been matched before. | |
void | setMatched (bool matched) |
Set if this key has been seen. | |
void | addData (PBuffer inputData) |
Add data node to this key. | |
uint | getAvgStorageSize () |
Get avg buffer size required to store all the fields based on TupleDescriptor information previously passed in init(). | |
uint | getStorageSize (TupleData const &inputTuple) |
Get actual buffer size required to store all the fields. | |
uint | getDiskStorageSize (TupleData const &inputTuple) |
Get actual disk size required to store all the fields. | |
void | checkStorageSize (TupleData const &inputTuple, uint maxBufferSize) |
Check that buffer size required to store all the fields does not exceed scratch buffer size. | |
void | pack (TupleData const &inputTuple) |
Store a tuple in the buffer associated with this accessor. | |
void | unpack (TupleData &outputTuple, TupleProjection &destProj) |
Retrieve the data stored in the buffer. | |
bool | matches (TupleData const &inputTuple, TupleProjection const &inputKeyProj) |
string | toString () |
Print the content of the node associated with this accessor. | |
PBuffer | getCurrent () |
| |
void | setCurrent (PBuffer nodePtrInit) |
Set the current node pointer for this accessor. | |
void | reset () |
Reset the node pointer to NULL. | |
PBuffer | getBuffer () |
| |
PBuffer | getNext () |
| |
PBuffer | getNextLocation () |
| |
void | setNext (PBuffer nextNode) |
Set the next node pointer for node associated with this accessor. | |
void | setNext (PBuffer inputNode, PBuffer nextNode) |
Set the next node pointer for an input node. | |
uint | getNextFieldSize () |
| |
uint | getBufferOffset () |
| |
Private Attributes | |
uint | firstDataOffset |
uint | isMatchedOffset |
uint | nextSlotOffset |
TupleDescriptor | keyDescriptor |
TupleData | keyTuple |
TupleAccessor | keyAccessor |
TupleProjection | keyColsProj |
TupleDescriptor | keyColsDesc |
TupleProjection | aggsProj |
TupleData | inputKey |
TupleData | currentKey |
LhxHashDataAccessor | firstData |
Definition at line 256 of file LhxHashTable.h.
LhxHashKeyAccessor::LhxHashKeyAccessor | ( | ) |
Definition at line 90 of file LhxHashTable.cpp.
References firstDataOffset, isMatchedOffset, and nextSlotOffset.
00091 : LhxHashNodeAccessor( 00092 sizeof(PBuffer) + sizeof(uint8_t) + sizeof(PBuffer *)) 00093 { 00094 firstDataOffset = 0; 00095 /* 00096 * firstData pointer is of type PBuffer 00097 */ 00098 isMatchedOffset = firstDataOffset + sizeof(PBuffer); 00099 /* 00100 * isMatched indicator is of type uint8_t 00101 */ 00102 nextSlotOffset = isMatchedOffset + sizeof(uint8_t); 00103 }
void LhxHashKeyAccessor::init | ( | TupleDescriptor const & | keyDescInit, | |
TupleProjection const & | keyColsProjInit, | |||
TupleProjection const & | aggsProjInit | |||
) |
Set the shape of the data tuple to be stored via this accessor.
[in] | keyDescInit | |
[in] | keyColsProjInit | the key fields |
[in] | aggsProjInit | the aggregate fields |
Definition at line 105 of file LhxHashTable.cpp.
References aggsProj, TupleAccessor::compute(), TupleData::compute(), keyAccessor, keyColsDesc, keyColsProj, keyDescriptor, keyTuple, and TupleDescriptor::projectFrom().
Referenced by LhxHashTable::calculateSize(), LhxHashTableReader::init(), and LhxHashTable::init().
00109 { 00110 keyDescriptor = keyDescInit; 00111 keyTuple.compute(keyDescriptor); 00112 keyAccessor.compute(keyDescriptor); 00113 00114 keyColsProj = keyColsProjInit; 00115 aggsProj = aggsProjInit; 00116 00117 keyColsDesc.projectFrom(keyDescriptor, keyColsProj); 00118 }
void LhxHashKeyAccessor::setCurrent | ( | PBuffer | nodePtrInit, | |
bool | valid | |||
) | [inline] |
Set the current node pointer for this accessor.
[in] | nodePtrInit | pointer to node that will be associated with this accessor |
[in] | valid | whether buffer content is valid. |
Definition at line 1178 of file LhxHashTable.h.
References LhxHashNodeAccessor::getBuffer(), keyAccessor, LhxHashNodeAccessor::setCurrent(), and TupleAccessor::setCurrentTupleBuf().
Referenced by LhxHashTable::addData(), LhxHashTable::addKeyData(), LhxHashTableReader::advanceKey(), LhxHashTableReader::advanceSlot(), LhxHashTable::aggData(), LhxHashTable::findKeyLocation(), LhxHashTable::getNextSlot(), and LhxHashTable::printSlot().
01179 { 01180 LhxHashNodeAccessor::setCurrent(nodePtrInit); 01181 keyAccessor.setCurrentTupleBuf(getBuffer(), valid); 01182 }
PBuffer LhxHashKeyAccessor::getFirstData | ( | ) | [inline] |
Get the first data node off this key node.
Definition at line 1201 of file LhxHashTable.h.
References firstDataOffset, and LhxHashNodeAccessor::getCurrent().
Referenced by addData(), LhxHashTableReader::advanceKey(), LhxHashTableReader::advanceSlot(), and LhxHashTable::printSlot().
01202 { 01203 PBuffer returnPtr; 01204 memcpy( 01205 (PBuffer) &returnPtr, 01206 (PBuffer) (getCurrent() + firstDataOffset), 01207 sizeof(PBuffer)); 01208 return returnPtr; 01209 }
void LhxHashKeyAccessor::setFirstData | ( | PBuffer | inputFirstData | ) | [inline] |
Set pointer to the first data node.
[in] | inputFirstData |
Definition at line 1211 of file LhxHashTable.h.
References firstDataOffset, and LhxHashNodeAccessor::getCurrent().
Referenced by addData(), and LhxHashTable::addKeyData().
01212 { 01213 memcpy( 01214 (PBuffer)(getCurrent() + firstDataOffset), 01215 (PBuffer)&inputFirstData, 01216 sizeof(PBuffer)); 01217 }
PBuffer * LhxHashKeyAccessor::getNextSlot | ( | ) | [inline] |
Get the first data node off this key node.
Definition at line 1219 of file LhxHashTable.h.
References LhxHashNodeAccessor::getCurrent(), and nextSlotOffset.
Referenced by LhxHashTable::addKeyData(), LhxHashTable::aggData(), LhxHashTable::getNextSlot(), and toString().
01220 { 01221 PBuffer *returnPtr; 01222 memcpy( 01223 (PBuffer) &returnPtr, 01224 (PBuffer) (getCurrent() + nextSlotOffset), 01225 sizeof(PBuffer *)); 01226 return returnPtr; 01227 }
void LhxHashKeyAccessor::setNextSlot | ( | PBuffer * | nextSlot | ) | [inline] |
Set pointer to the first data node.
[in] | nextSlot |
Definition at line 1229 of file LhxHashTable.h.
References LhxHashNodeAccessor::getCurrent(), and nextSlotOffset.
Referenced by LhxHashTable::addKeyData(), and LhxHashTable::aggData().
01230 { 01231 memcpy( 01232 (PBuffer)(getCurrent() + nextSlotOffset), 01233 (PBuffer)&nextSlot, 01234 sizeof(PBuffer*)); 01235 }
bool LhxHashKeyAccessor::isMatched | ( | ) | [inline] |
Check if this key has been matched before.
Definition at line 1237 of file LhxHashTable.h.
References LhxHashNodeAccessor::getCurrent(), and isMatchedOffset.
Referenced by LhxHashTableReader::advanceKey(), LhxHashTableReader::advanceSlot(), LhxHashTable::findKeyLocation(), and toString().
01238 { 01239 return (*(uint8_t *)(getCurrent() + isMatchedOffset) == 1); 01240 }
void LhxHashKeyAccessor::setMatched | ( | bool | matched | ) | [inline] |
Set if this key has been seen.
[in] | matched |
Definition at line 1242 of file LhxHashTable.h.
References LhxHashNodeAccessor::getCurrent(), and isMatchedOffset.
Referenced by LhxHashTable::addKeyData(), LhxHashTable::aggData(), and LhxHashTable::findKeyLocation().
01243 { 01244 *(getCurrent() + isMatchedOffset) = (matched ? 0x01 : 0); 01245 }
void LhxHashKeyAccessor::addData | ( | PBuffer | inputData | ) |
Add data node to this key.
[in] | inputData |
Definition at line 120 of file LhxHashTable.cpp.
References firstData, getFirstData(), setFirstData(), and LhxHashNodeAccessor::setNext().
Referenced by LhxHashTable::addData(), and LhxHashTable::addKeyData().
00121 { 00122 PBuffer firstDataNode = getFirstData(); 00123 /* 00124 * The original first data node becomes the next. 00125 */ 00126 firstData.setNext(inputData, firstDataNode); 00127 setFirstData(inputData); 00128 }
uint LhxHashKeyAccessor::getAvgStorageSize | ( | ) | [inline] |
Get avg buffer size required to store all the fields based on TupleDescriptor information previously passed in init().
This function needs to be called after calling init().
Definition at line 1184 of file LhxHashTable.h.
References LhxHashNodeAccessor::getBufferOffset(), TupleAccessor::getMaxByteCount(), TupleAccessor::getMinByteCount(), and keyAccessor.
Referenced by LhxHashTable::calculateSize().
01185 { 01186 return 01187 ((keyAccessor.getMaxByteCount() + keyAccessor.getMinByteCount()) / 2) + 01188 getBufferOffset(); 01189 }
Get actual buffer size required to store all the fields.
[in] | inputTuple | get the storage size for this inputTuple. |
Definition at line 1191 of file LhxHashTable.h.
References LhxHashNodeAccessor::getBufferOffset(), TupleAccessor::getByteCount(), and keyAccessor.
Referenced by LhxHashTable::addKeyData(), LhxHashTable::aggData(), and checkStorageSize().
01192 { 01193 return keyAccessor.getByteCount(inputTuple) + getBufferOffset(); 01194 }
Get actual disk size required to store all the fields.
[in] | inputTuple | get the storage size for this inputTuple. |
Definition at line 1196 of file LhxHashTable.h.
References TupleAccessor::getByteCount(), and keyAccessor.
01197 { 01198 return keyAccessor.getByteCount(inputTuple); 01199 }
void LhxHashKeyAccessor::checkStorageSize | ( | TupleData const & | inputTuple, | |
uint | maxBufferSize | |||
) | [inline] |
Check that buffer size required to store all the fields does not exceed scratch buffer size.
[in] | inputTuple | if NULL get the tuple storage size for the buffer associated with this accessor; else get the storage size for the inputTuple. |
[in] | maxBufferSize | maximum buffer size |
Definition at line 1247 of file LhxHashTable.h.
References getStorageSize(), and keyDescriptor.
Referenced by LhxHashTable::addKeyData(), and LhxHashTable::aggData().
01250 { 01251 uint storageSize = getStorageSize(inputTuple); 01252 01253 if (storageSize > maxBufferSize) { 01254 throw TupleOverflowExcn( 01255 keyDescriptor, 01256 inputTuple, 01257 storageSize, 01258 maxBufferSize); 01259 } 01260 }
void LhxHashKeyAccessor::pack | ( | TupleData const & | inputTuple | ) | [inline] |
Store a tuple in the buffer associated with this accessor.
Has to be called before trying to match any input with this key.
[in] | inputTuple |
Definition at line 1153 of file LhxHashTable.h.
References LhxHashNodeAccessor::getBuffer(), keyAccessor, TupleAccessor::marshal(), and TupleAccessor::size().
Referenced by LhxHashTable::addKeyData(), and LhxHashTable::aggData().
01154 { 01155 PBuffer buf = getBuffer(); 01156 01157 assert(buf != NULL && inputTuple.size() == keyAccessor.size()); 01158 01159 /* 01160 * Copy the input tuple into the buffer associated with this accessor. 01161 */ 01162 keyAccessor.marshal(inputTuple, buf); 01163 }
void LhxHashKeyAccessor::unpack | ( | TupleData & | outputTuple, | |
TupleProjection & | destProj | |||
) |
Retrieve the data stored in the buffer.
Upon return, outputTuple will point into the buffer associated with this accessor.
[out] | outputTuple | |
[out] | destProj | fields to copy to in the outputTuple |
Definition at line 130 of file LhxHashTable.cpp.
References LhxHashNodeAccessor::getBuffer(), keyAccessor, keyTuple, min(), and TupleAccessor::unmarshal().
Referenced by LhxHashTable::aggData(), LhxHashTableReader::produceTuple(), and toString().
00133 { 00134 PBuffer buf = getBuffer(); 00135 00136 assert (buf != NULL); 00137 00138 if (destProj.size() > 0) { 00139 /* 00140 * Destination positions in the outputTuple should be enough to hold 00141 * fields returned by dataAccessor. 00142 */ 00143 uint tupleSize = min(destProj.size(), keyTuple.size()); 00144 00145 /* 00146 * Set pointers in the tmp tuple, and then pass them on to fields in 00147 * output tuple. 00148 */ 00149 keyAccessor.unmarshal(keyTuple); 00150 00151 for (int i = 0; i < tupleSize; i ++) { 00152 outputTuple[destProj[i]].copyFrom(keyTuple[i]); 00153 } 00154 } else { 00155 /* 00156 * Set pointers in the outputtuple. 00157 */ 00158 keyAccessor.unmarshal(outputTuple); 00159 } 00160 }
bool LhxHashKeyAccessor::matches | ( | TupleData const & | inputTuple, | |
TupleProjection const & | inputKeyProj | |||
) |
Definition at line 162 of file LhxHashTable.cpp.
References TupleDescriptor::compareTuples(), currentKey, inputKey, keyAccessor, keyColsDesc, keyColsProj, keyTuple, TupleData::projectFrom(), and TupleAccessor::unmarshal().
Referenced by LhxHashTable::findKeyLocation().
00165 { 00166 assert(inputKeyProj.size() == keyColsProj.size()); 00167 00168 inputKey.projectFrom(inputTuple, inputKeyProj); 00169 00170 keyAccessor.unmarshal(keyTuple); 00171 00172 currentKey.projectFrom(keyTuple, keyColsProj); 00173 00174 return keyColsDesc.compareTuples( 00175 keyTuple, keyColsProj, 00176 inputTuple, inputKeyProj) == 0; 00177 }
string LhxHashKeyAccessor::toString | ( | ) |
Print the content of the node associated with this accessor.
Definition at line 179 of file LhxHashTable.cpp.
References TupleData::compute(), getNextSlot(), isMatched(), keyDescriptor, keyTuple, TuplePrinter::print(), and unpack().
Referenced by LhxHashTable::printSlot().
00180 { 00181 TuplePrinter tuplePrinter; 00182 ostringstream keyTrace; 00183 TupleProjection allFields; 00184 allFields.clear(); 00185 00186 keyTuple.compute(keyDescriptor); 00187 unpack(keyTuple, allFields); 00188 keyTrace << "[Key Node] [" 00189 << (isMatched() ? "matched" : "unmatched") 00190 << " next " << getNextSlot() << "] "; 00191 tuplePrinter.print(keyTrace, keyDescriptor, keyTuple); 00192 return keyTrace.str(); 00193 }
PBuffer LhxHashNodeAccessor::getCurrent | ( | ) | [inline, inherited] |
Definition at line 1051 of file LhxHashTable.h.
References LhxHashNodeAccessor::nodePtr.
Referenced by getFirstData(), getNextSlot(), LhxHashBlockAccessor::getSlot(), isMatched(), setFirstData(), setMatched(), and setNextSlot().
01052 { 01053 return nodePtr; 01054 }
void LhxHashNodeAccessor::setCurrent | ( | PBuffer | nodePtrInit | ) | [inline, inherited] |
Set the current node pointer for this accessor.
[in] | nodePtrInit | pointer to node that will be associated with this accessor |
Definition at line 1061 of file LhxHashTable.h.
References LhxHashNodeAccessor::nodePtr.
Referenced by LhxHashNodeAccessor::reset(), setCurrent(), LhxHashDataAccessor::setCurrent(), and LhxHashBlockAccessor::setCurrent().
01062 { 01063 nodePtr = nodePtrInit; 01064 }
void LhxHashNodeAccessor::reset | ( | ) | [inline, inherited] |
Reset the node pointer to NULL.
Reimplemented in LhxHashBlockAccessor.
Definition at line 1066 of file LhxHashTable.h.
References LhxHashNodeAccessor::setCurrent().
Referenced by LhxHashTable::releaseResources(), and LhxHashBlockAccessor::reset().
01067 { 01068 setCurrent(NULL); 01069 }
PBuffer LhxHashNodeAccessor::getBuffer | ( | ) | [inline, inherited] |
Definition at line 1056 of file LhxHashTable.h.
References LhxHashNodeAccessor::nodeBufferOffset, and LhxHashNodeAccessor::nodePtr.
Referenced by LhxHashBlockAccessor::getSlot(), LhxHashDataAccessor::pack(), pack(), setCurrent(), LhxHashDataAccessor::setCurrent(), LhxHashBlockAccessor::setCurrent(), unpack(), and LhxHashDataAccessor::unpack().
01057 { 01058 return (nodePtr + nodeBufferOffset); 01059 }
PBuffer LhxHashNodeAccessor::getNext | ( | ) | [inline, inherited] |
Definition at line 1071 of file LhxHashTable.h.
References LhxHashNodeAccessor::nextNodeOffset, and LhxHashNodeAccessor::nodePtr.
Referenced by LhxHashTableReader::advanceData(), LhxHashTableReader::advanceKey(), LhxHashTableReader::advanceSlot(), LhxHashTable::aggData(), LhxHashTable::allocateResources(), LhxHashTable::allocBuffer(), LhxHashTable::findKeyLocation(), and LhxHashTable::printSlot().
01072 { 01073 // REVIEW jvs 25-Aug-2006: Under what circumstances would 01074 // alignment be off? Tuple sizes are always aligned. Is it 01075 // because of the match indicator? If so, it might make sense to 01076 // fold that into the tuple. 01077 /* 01078 * nodePtr+nextNodeOffset might not be aligned so copy the pointer 01079 * value out. 01080 */ 01081 PBuffer returnPtr; 01082 memcpy((PBuffer)&returnPtr, nodePtr+nextNodeOffset, sizeof(PBuffer)); 01083 return returnPtr; 01084 }
PBuffer LhxHashNodeAccessor::getNextLocation | ( | ) | [inline, inherited] |
Definition at line 1086 of file LhxHashTable.h.
References LhxHashNodeAccessor::nextNodeOffset, and LhxHashNodeAccessor::nodePtr.
Referenced by LhxHashTable::findKeyLocation().
01087 { 01088 return nodePtr + nextNodeOffset; 01089 }
void LhxHashNodeAccessor::setNext | ( | PBuffer | nextNode | ) | [inline, inherited] |
Set the next node pointer for node associated with this accessor.
[in] | nextNode | pointer to the next node |
Definition at line 1091 of file LhxHashTable.h.
References LhxHashNodeAccessor::getNextFieldSize(), LhxHashNodeAccessor::nextNodeOffset, and LhxHashNodeAccessor::nodePtr.
Referenced by addData(), LhxHashTable::addKeyData(), LhxHashTable::aggData(), LhxHashTable::allocateResources(), LhxHashTable::allocBlock(), and LhxHashTable::allocBuffer().
01092 { 01093 memcpy(nodePtr+nextNodeOffset, (PBuffer)&nextNode, getNextFieldSize()); 01094 }
Set the next node pointer for an input node.
[in] | inputNode | input node to set the next node pointer |
[in] | nextNode | pointer to the next node |
Definition at line 1096 of file LhxHashTable.h.
References LhxHashNodeAccessor::getNextFieldSize(), and LhxHashNodeAccessor::nextNodeOffset.
01097 { 01098 memcpy(inputNode+nextNodeOffset, (PBuffer)&nextNode, getNextFieldSize()); 01099 }
uint LhxHashNodeAccessor::getNextFieldSize | ( | ) | [inline, inherited] |
Definition at line 1101 of file LhxHashTable.h.
Referenced by LhxHashNodeAccessor::LhxHashNodeAccessor(), and LhxHashNodeAccessor::setNext().
01102 { 01103 return sizeof(PBuffer); 01104 }
uint LhxHashNodeAccessor::getBufferOffset | ( | ) | [inline, inherited] |
This is equivalent to the total space used for the variable length payload.
Definition at line 1106 of file LhxHashTable.h.
References LhxHashNodeAccessor::nodeBufferOffset.
Referenced by getAvgStorageSize(), LhxHashDataAccessor::getAvgStorageSize(), getStorageSize(), LhxHashDataAccessor::getStorageSize(), and LhxHashBlockAccessor::init().
01107 { 01108 return nodeBufferOffset; 01109 }
uint LhxHashKeyAccessor::firstDataOffset [private] |
Definition at line 262 of file LhxHashTable.h.
Referenced by getFirstData(), LhxHashKeyAccessor(), and setFirstData().
uint LhxHashKeyAccessor::isMatchedOffset [private] |
Definition at line 268 of file LhxHashTable.h.
Referenced by isMatched(), LhxHashKeyAccessor(), and setMatched().
uint LhxHashKeyAccessor::nextSlotOffset [private] |
Definition at line 273 of file LhxHashTable.h.
Referenced by getNextSlot(), LhxHashKeyAccessor(), and setNextSlot().
Definition at line 278 of file LhxHashTable.h.
Referenced by checkStorageSize(), init(), and toString().
TupleData LhxHashKeyAccessor::keyTuple [private] |
Definition at line 283 of file LhxHashTable.h.
Referenced by init(), matches(), toString(), and unpack().
TupleAccessor LhxHashKeyAccessor::keyAccessor [private] |
Definition at line 288 of file LhxHashTable.h.
Referenced by getAvgStorageSize(), getDiskStorageSize(), getStorageSize(), init(), matches(), pack(), setCurrent(), and unpack().
TupleProjection LhxHashKeyAccessor::aggsProj [private] |
TupleData LhxHashKeyAccessor::inputKey [private] |
TupleData LhxHashKeyAccessor::currentKey [private] |