TupleSchema* TupleSchema::createTupleSchema(const std::vector<ValueType>& columnTypes, const std::vector<int32_t>& columnSizes, const std::vector<bool>& allowNull, const std::vector<bool>& columnInBytes, const std::vector<ValueType>& hiddenColumnTypes, const std::vector<int32_t>& hiddenColumnSizes, const std::vector<bool>& hiddenAllowNull, const std::vector<bool>& hiddenColumnInBytes) { const uint16_t uninlineableObjectColumnCount = TupleSchema::countUninlineableObjectColumns(columnTypes, columnSizes, columnInBytes); const uint16_t columnCount = static_cast<uint16_t>(columnTypes.size()); const uint16_t hiddenColumnCount = static_cast<uint16_t>(hiddenColumnTypes.size()); int memSize = memSizeForTupleSchema(columnCount, uninlineableObjectColumnCount, hiddenColumnCount); // allocate the set amount of memory and cast it to a tuple pointer TupleSchema *retval = reinterpret_cast<TupleSchema*>(new char[memSize]); // clear all the offset values memset(retval, 0, memSize); retval->m_columnCount = columnCount; retval->m_uninlinedObjectColumnCount = uninlineableObjectColumnCount; retval->m_hiddenColumnCount = hiddenColumnCount; retval->m_isHeaderless = false; uint16_t uninlinedObjectColumnIndex = 0; for (uint16_t ii = 0; ii < columnCount; ii++) { const ValueType type = columnTypes[ii]; const uint32_t length = columnSizes[ii]; const bool columnAllowNull = allowNull[ii]; const bool inBytes = columnInBytes[ii]; retval->setColumnMetaData(ii, type, length, columnAllowNull, uninlinedObjectColumnIndex, inBytes); } for (uint16_t ii = 0; ii < hiddenColumnCount; ++ii) { const ValueType type = hiddenColumnTypes[ii]; const uint32_t length = hiddenColumnSizes[ii]; const bool columnAllowNull = hiddenAllowNull[ii]; const bool inBytes = hiddenColumnInBytes[ii]; // We can't allow uninlineable data in hidden columns yet if (! isInlineable(type, length, inBytes)) { throwFatalLogicErrorStreamed("Attempt to create uninlineable hidden column"); } retval->setColumnMetaData(static_cast<uint16_t>(columnCount + ii), type, length, columnAllowNull, uninlinedObjectColumnIndex, inBytes); } return retval; }
TupleSchema* TupleSchema::createTupleSchema(const std::vector<ValueType> columnTypes, const std::vector<int32_t> columnSizes, const std::vector<bool> allowNull, bool allowInlinedObjects) { const uint16_t uninlineableObjectColumnCount = TupleSchema::countUninlineableObjectColumns(columnTypes, columnSizes, allowInlinedObjects); const uint16_t columnCount = static_cast<uint16_t>(columnTypes.size()); // big enough for any data members plus big enough for tupleCount + 1 "ColumnInfo" // fields. We need CI+1 because we get the length of a column by offset subtraction // Also allocate space for an int16_t for each uninlineable object column so that // the indices of uninlineable columns can be stored at the front and aid in iteration int memSize = (int)(sizeof(TupleSchema) + (sizeof(ColumnInfo) * (columnCount + 1)) + (uninlineableObjectColumnCount * sizeof(int16_t))); // allocate the set amount of memory and cast it to a tuple pointer TupleSchema *retval = reinterpret_cast<TupleSchema*>(new char[memSize]); // clear all the offset values memset(retval, 0, memSize); retval->m_allowInlinedObjects = allowInlinedObjects; retval->m_columnCount = columnCount; retval->m_uninlinedObjectColumnCount = uninlineableObjectColumnCount; uint16_t uninlinedObjectColumnIndex = 0; for (uint16_t ii = 0; ii < columnCount; ii++) { const ValueType type = columnTypes[ii]; const uint32_t length = columnSizes[ii]; const bool columnAllowNull = allowNull[ii]; retval->setColumnMetaData(ii, type, length, columnAllowNull, uninlinedObjectColumnIndex); } return retval; }