#include <TupleDescriptor.h>
Public Member Functions | |
void | projectFrom (TupleDescriptor const &tupleDescriptor, TupleProjection const &tupleProjection) |
int | compareTuplesKey (TupleData const &tuple1, TupleData const &tuple2, uint keyCount) const |
int | compareTuples (TupleData const &tuple1, TupleData const &tuple2) const |
int | compareTuples (TupleData const &tuple1, TupleProjection const &proj1, TupleData const &tuple2, TupleProjection const &proj2, bool *containsNullKey=NULL) const |
void | writePersistent (ByteOutputStream &) const |
void | readPersistent (ByteInputStream &, StoredTypeDescriptorFactory const &) |
void | visit (TupleData const &tuple, DataVisitor &dataVisitor, bool visitLengths) const |
bool | containsNullable () const |
bool | storageEqual (TupleDescriptor const &other) const |
Performs a comparison only of type & size, not nullability. | |
TupleStorageByteLength | getMaxByteCount () const |
The compareTuples[Key] methods return the standard zero, negative, or positive to indicate EQ, LT, GT. However, rather than returning -1 or 1 for LT/GT, they return the 1-based ordinal of the first non-equal column (negated if LT). This allows a caller to implement ORDER BY DESC without having to pass in ASC/DESC information.
Definition at line 89 of file TupleDescriptor.h.
void TupleDescriptor::projectFrom | ( | TupleDescriptor const & | tupleDescriptor, | |
TupleProjection const & | tupleProjection | |||
) |
Definition at line 72 of file TupleDescriptor.cpp.
Referenced by BTreeAccessBase::BTreeAccessBase(), LhxHashTable::calculateSize(), LhxHashKeyAccessor::init(), ReshapeExecStream::initCompareData(), LbmExecStreamTestBase::initNormalizerExecStream(), LcsClusterReplaceExecStream::initTupleLoadParams(), LcsClusterAppendExecStream::initTupleLoadParams(), FtrsTableWriterFactory::loadIndex(), ExternalSortExecStreamImpl::prepare(), LbmNormalizerExecStream::prepare(), LhxJoinExecStream::prepare(), BTreeSearchExecStream::prepare(), ReshapeExecStream::prepare(), LcsRowScanExecStream::prepareResidualFilters(), LhxAggExecStream::setHashInfo(), LbmSortedAggExecStreamTest::testSortedAgg(), and BTreeBuilder::truncateExternal().
00075 { 00076 clear(); 00077 for (uint i = 0; i < tupleProjection.size(); ++i) { 00078 push_back(tupleDescriptor[tupleProjection[i]]); 00079 } 00080 }
int TupleDescriptor::compareTuplesKey | ( | TupleData const & | tuple1, | |
TupleData const & | tuple2, | |||
uint | keyCount | |||
) | const |
Definition at line 137 of file TupleDescriptor.cpp.
References min(), and TupleDatum::pData.
Referenced by LbmEntry::compareEntry(), ReshapeExecStream::compareInput(), compareTuples(), LbmSplicerExecStream::findBTreeEntry(), LbmSplicerExecStream::getValidatedTuple(), BTreeSearchExecStream::testInterval(), and BTreePrefetchSearchExecStream::testNonLeafInterval().
00141 { 00142 assert(keyCount <= std::min(tuple1.size(), tuple2.size())); 00143 00144 for (uint i = 0; i < keyCount; ++i) { 00145 TupleDatum const &datum1 = tuple1[i]; 00146 TupleDatum const &datum2 = tuple2[i]; 00147 // TODO: parameterize NULL-value collation 00148 if (!datum1.pData) { 00149 if (!datum2.pData) { 00150 continue; 00151 } 00152 return -(i + 1); 00153 } else if (!datum2.pData) { 00154 return (i + 1); 00155 } 00156 int c = (*this)[i].pTypeDescriptor->compareValues( 00157 datum1.pData, 00158 datum1.cbData, 00159 datum2.pData, 00160 datum2.cbData); 00161 if (c > 0) { 00162 return (i + 1); 00163 } else if (c < 0) { 00164 return -(i + 1); 00165 } 00166 } 00167 return 0; 00168 }
Definition at line 82 of file TupleDescriptor.cpp.
References compareTuplesKey(), and min().
Referenced by LcsColumnReader::applyFilters(), BTreeKeyedNodeAccessor< NodeAccessor, KeyAccessor >::binarySearch(), BTreeWriter::checkMonotonicity(), BTreeSearchExecStream::checkNextKey(), BTreeKeyedNodeAccessor< NodeAccessor, KeyAccessor >::compareFirstKey(), ReshapeExecStream::compareInput(), ExternalSortInfo::compareKeys(), LcsColumnReader::findVal(), LcsCompareColKeyUsingOffsetIndex::lessThan(), LhxHashKeyAccessor::matches(), LcsHash::search(), BTreeSearchExecStream::testInterval(), BTreePrefetchSearchExecStream::testNonLeafInterval(), LbmReaderTest::testSingleTupleReader(), ExecStreamUnitTestBase::verifyBufferedOutput(), and BTreeVerifier::verifyNode().
00085 { 00086 int keyComp; 00087 // REVIEW: should pass n as a param instead of recalculating it each time 00088 size_t keyCount = std::min(tuple1.size(),tuple2.size()); 00089 keyCount = std::min(keyCount,size()); 00090 keyComp = compareTuplesKey(tuple1, tuple2, keyCount); 00091 return keyComp; 00092 }
int TupleDescriptor::compareTuples | ( | TupleData const & | tuple1, | |
TupleProjection const & | proj1, | |||
TupleData const & | tuple2, | |||
TupleProjection const & | proj2, | |||
bool * | containsNullKey = NULL | |||
) | const |
Definition at line 94 of file TupleDescriptor.cpp.
References min(), and TupleDatum::pData.
00098 { 00099 size_t keyCount = std::min(proj1.size(), proj2.size()); 00100 00101 if (containsNullKey) { 00102 *containsNullKey = false; 00103 } 00104 for (uint i = 0; i < keyCount; ++i) { 00105 TupleDatum const &datum1 = tuple1[proj1[i]]; 00106 TupleDatum const &datum2 = tuple2[proj2[i]]; 00107 // TODO: parameterize NULL-value collation 00108 if (!datum1.pData) { 00109 if (containsNullKey) { 00110 *containsNullKey = true; 00111 } 00112 if (!datum2.pData) { 00113 continue; 00114 } 00115 return -(i + 1); 00116 } else if (!datum2.pData) { 00117 if (containsNullKey) { 00118 *containsNullKey = true; 00119 } 00120 return (i + 1); 00121 } 00122 int c = (*this)[i].pTypeDescriptor->compareValues( 00123 datum1.pData, 00124 datum1.cbData, 00125 datum2.pData, 00126 datum2.cbData); 00127 if (c > 0) { 00128 return (i + 1); 00129 } else if (c < 0) { 00130 return -(i + 1); 00131 } 00132 } 00133 return 0; 00134 00135 }
void TupleDescriptor::writePersistent | ( | ByteOutputStream & | ) | const |
Definition at line 199 of file TupleDescriptor.cpp.
References ByteOutputStream::writeValue().
Referenced by FtrsTableWriter::describeParticipant(), and BTreeWriter::describeParticipant().
00200 { 00201 uint32_t iData = htonl(size()); 00202 stream.writeValue(iData); 00203 for (uint i = 0; i < size(); ++i) { 00204 TupleAttributeDescriptor const &attrDesc = (*this)[i]; 00205 iData = htonl(attrDesc.pTypeDescriptor->getOrdinal()); 00206 stream.writeValue(iData); 00207 iData = htonl(attrDesc.isNullable); 00208 stream.writeValue(iData); 00209 // Assume TupleAttributeDescriptor is long in htonl() 00210 iData = htonl(attrDesc.cbStorage); 00211 stream.writeValue(iData); 00212 } 00213 }
void TupleDescriptor::readPersistent | ( | ByteInputStream & | , | |
StoredTypeDescriptorFactory const & | ||||
) |
Definition at line 215 of file TupleDescriptor.cpp.
References StoredTypeDescriptorFactory::newDataType(), and ByteInputStream::readValue().
Referenced by FtrsTableWriterFactory::loadParticipant(), and BTreeRecoveryFactory::loadParticipant().
00218 { 00219 clear(); 00220 uint32_t n; 00221 stream.readValue(n); 00222 n = ntohl(n); 00223 for (uint i = 0; i < n; ++i) { 00224 uint32_t iData; 00225 stream.readValue(iData); 00226 StoredTypeDescriptor const &typeDescriptor = 00227 typeFactory.newDataType(ntohl(iData)); 00228 stream.readValue(iData); 00229 bool isNullable = ntohl(iData); 00230 stream.readValue(iData); 00231 TupleStorageByteLength cbStorage = ntohl(iData); 00232 push_back( 00233 TupleAttributeDescriptor( 00234 typeDescriptor,isNullable,cbStorage)); 00235 } 00236 }
void TupleDescriptor::visit | ( | TupleData const & | tuple, | |
DataVisitor & | dataVisitor, | |||
bool | visitLengths | |||
) | const |
Definition at line 170 of file TupleDescriptor.cpp.
References DataVisitor::visitBytes(), and DataVisitor::visitUnsignedInt().
Referenced by TuplePrinter::print().
00174 { 00175 for (uint i = 0; i < tuple.size(); ++i) { 00176 if (!tuple[i].pData) { 00177 if (visitLengths) { 00178 dataVisitor.visitUnsignedInt(0); 00179 } 00180 dataVisitor.visitBytes(NULL,0); 00181 } else { 00182 if (visitLengths) { 00183 dataVisitor.visitUnsignedInt(tuple[i].cbData); 00184 } 00185 (*this)[i].pTypeDescriptor->visitValue( 00186 dataVisitor, 00187 tuple[i].pData, 00188 tuple[i].cbData); 00189 } 00190 } 00191 }
bool TupleDescriptor::containsNullable | ( | ) | const |
Definition at line 273 of file TupleDescriptor.cpp.
Referenced by BTreeSearchExecStream::prepare().
00274 { 00275 for (uint i = 0; i < size(); ++i) { 00276 if ((*this)[i].isNullable) { 00277 return true; 00278 } 00279 } 00280 return false; 00281 }
bool TupleDescriptor::storageEqual | ( | TupleDescriptor const & | other | ) | const |
Performs a comparison only of type & size, not nullability.
Definition at line 283 of file TupleDescriptor.cpp.
References TupleAttributeDescriptor::cbStorage, StoredTypeDescriptor::getOrdinal(), and TupleAttributeDescriptor::pTypeDescriptor.
Referenced by CalcExecStream::prepare().
00285 { 00286 uint sz = size(); 00287 if (other.size() != sz) { 00288 return false; 00289 } 00290 00291 TupleAttributeDescriptor const * us; 00292 TupleAttributeDescriptor const * them; 00293 00294 for (uint i = 0; i < sz; ++i) { 00295 us = &(*this)[i]; 00296 them = &other[i]; 00297 if ((us->pTypeDescriptor->getOrdinal() != 00298 them->pTypeDescriptor->getOrdinal()) || 00299 us->cbStorage != them->cbStorage) { 00300 return false; 00301 } 00302 } 00303 return true; 00304 }
TupleStorageByteLength TupleDescriptor::getMaxByteCount | ( | ) | const |
Definition at line 306 of file TupleDescriptor.cpp.
Referenced by LbmEntry::getSizeBounds().
00307 { 00308 TupleStorageByteLength length = 0; 00309 00310 for (uint i = 0; i < size(); i ++) { 00311 length += (*this)[i].cbStorage; 00312 } 00313 return length; 00314 }