size_t DRTupleStream::computeOffsets(TableTuple &tuple, size_t *rowHeaderSz) { // round-up columncount to next multiple of 8 and divide by 8 const int columnCount = tuple.sizeInValues(); int nullMaskLength = ((columnCount + 7) & -8) >> 3; // row header is 32-bit length of row plus null mask *rowHeaderSz = sizeof(int32_t) + nullMaskLength; //Can return 0 for a single column varchar with null size_t dataSz = tuple.maxExportSerializationSize(); return *rowHeaderSz + dataSz; }
// helper to make a schema, a tuple and calculate EL size size_t TableTupleExportTest::maxElSize(std::vector<uint16_t> &keep_offsets, bool useNullStrings) { TableTuple *tt; TupleSchema *ts; char buf[1024]; // tuple data ts = TupleSchema::createTupleSchema(m_schema, keep_offsets); tt = new TableTuple(buf, ts); // if the tuple includes strings, add some content // assuming all Export tuples were allocated for persistent // storage and choosing set* api accordingly here. if (ts->columnCount() > 6) { NValue nv = ValueFactory::getStringValue("ABCDEabcde"); // 10 char if (useNullStrings) { nv.free(); nv.setNull(); } tt->setNValueAllocateForObjectCopies(6, nv, NULL); nv.free(); } if (ts->columnCount() > 7) { NValue nv = ValueFactory::getStringValue("abcdeabcdeabcdeabcde"); // 20 char if (useNullStrings) { nv.free(); nv.setNull(); } tt->setNValueAllocateForObjectCopies(7, nv, NULL); nv.free(); } // The function under test! size_t sz = tt->maxExportSerializationSize(); // and cleanup tt->freeObjectColumns(); delete tt; TupleSchema::freeTupleSchema(ts); return sz; }
size_t TupleStreamWrapper::computeOffsets(TableTuple &tuple, size_t *rowHeaderSz) { // round-up columncount to next multiple of 8 and divide by 8 int columnCount = tuple.sizeInValues() + METADATA_COL_CNT; int nullMaskLength = ((columnCount + 7) & -8) >> 3; // row header is 32-bit length of row plus null mask *rowHeaderSz = sizeof (int32_t) + nullMaskLength; // metadata column width: 5 int64_ts plus CHAR(1). size_t metadataSz = (sizeof (int64_t) * 5) + 1; // returns 0 if corrupt tuple detected size_t dataSz = tuple.maxExportSerializationSize(); if (dataSz == 0) { throwFatalException("Invalid tuple passed to computeTupleMaxLength. Crashing System."); } return *rowHeaderSz + metadataSz + dataSz; }