Exemple #1
0
void TupleSchema::setColumnMetaData(uint16_t index, ValueType type, const int32_t length, bool allowNull,
                                    uint16_t &uninlinedObjectColumnIndex, bool inBytes)
{
    assert(length <= COLUMN_MAX_VALUE_LENGTH);
    uint32_t offset = 0;

    // set the type
    ColumnInfo *columnInfo = getColumnInfoPrivate(index);
    columnInfo->type = static_cast<char>(type);
    columnInfo->allowNull = (char)(allowNull ? 1 : 0);
    columnInfo->length = length;
    columnInfo->inBytes = inBytes;

    if (type == VALUE_TYPE_VARCHAR || type == VALUE_TYPE_VARBINARY) {
        if (length == 0) {
            throwFatalLogicErrorStreamed("Zero length for object type " << valueToString((ValueType)type));
        }

        if (isInlineable(type, length, inBytes)) {
            columnInfo->inlined = true;

            // If the length was specified in characters, convert to bytes.
            int32_t factor = (type == VALUE_TYPE_VARCHAR && !inBytes) ? MAX_BYTES_PER_UTF8_CHARACTER : 1;

            // inlined variable length columns have a size prefix (1 byte)
            offset = static_cast<uint32_t>(SHORT_OBJECT_LENGTHLENGTH + (length * factor));
        } else {
            columnInfo->inlined = false;

            // Set the length to the size of a String pointer since it won't be inlined.
            offset = static_cast<uint32_t>(NValue::getTupleStorageSize(type));

            setUninlinedObjectColumnInfoIndex(uninlinedObjectColumnIndex++, index);
        }
    } else {
        // All values are inlined if they aren't strings.
        columnInfo->inlined = true;
        // don't trust the planner since it can be avoided
        offset = static_cast<uint32_t>(NValue::getTupleStorageSize(type));
    }
    // make the column offsets right for all columns past this one
    int oldsize = columnLengthPrivate(index);
    ColumnInfo *nextColumnInfo = NULL;
    for (int i = index + 1; i <= totalColumnCount(); i++) {
        nextColumnInfo = getColumnInfoPrivate(i);
        nextColumnInfo->offset = static_cast<uint32_t>(nextColumnInfo->offset + offset - oldsize);
    }
    assert(index == 0 ? columnInfo->offset == 0 : true);
}
Exemple #2
0
// GWW: escrow column
void TupleSchema::setColumnMetaData(uint16_t index, ValueType type, const int32_t length, bool allowNull,
                                    bool escrowColumn, uint16_t &uninlinedObjectColumnIndex)
{
    assert(length <= 1048576);
    uint32_t offset = 0;

    // set the type
    ColumnInfo *columnInfo = getColumnInfo(index);
    columnInfo->type = static_cast<char>(type);
    columnInfo->allowNull = (char)(allowNull ? 1 : 0);
    // GWW
    columnInfo->escrowCol = escrowColumn;
    columnInfo->length = length;
    if ((type == VALUE_TYPE_VARCHAR) || (type == VALUE_TYPE_VARBINARY)) {
        if (length < UNINLINEABLE_OBJECT_LENGTH && m_allowInlinedObjects) {
            /*
             * Inline the string if it is less then UNINLINEABLE_OBJECT_LENGTH bytes.
             */
            columnInfo->inlined = true;
            // One byte to store the size
            offset = static_cast<uint32_t>(length + SHORT_OBJECT_LENGTHLENGTH);
        } else {
            /*
             * Set the length to the size of a String pointer since it won't be inlined.
             */
            offset = static_cast<uint32_t>(NValue::getTupleStorageSize(type));
            columnInfo->inlined = false;
            setUninlinedObjectColumnInfoIndex(uninlinedObjectColumnIndex++, index);
        }
    } else {
        // All values are inlined if they aren't strings.
        columnInfo->inlined = true;
        // don't trust the planner since it can be avoided
        offset = static_cast<uint32_t>(NValue::getTupleStorageSize(type));
    }
    // make the column offsets right for all columns past this one
    int oldsize = columnLengthPrivate(index);
    ColumnInfo *nextColumnInfo = NULL;
    for (int i = index + 1; i <= m_columnCount; i++) {
        nextColumnInfo = getColumnInfo(i);
        nextColumnInfo->offset = static_cast<uint32_t>(nextColumnInfo->offset + offset - oldsize);
    }
    assert(index == 0 ? columnInfo->offset == 0 : true);
}
Exemple #3
0
void TupleSchema::setColumnMetaData(uint16_t index, ValueType type, const int32_t length, bool allowNull,
                                    uint16_t &uninlinedObjectColumnIndex, bool inBytes)
{
    assert(length <= COLUMN_MAX_VALUE_LENGTH);
    uint32_t offset = 0;

    // set the type
    ColumnInfo *columnInfo = getColumnInfo(index);
    columnInfo->type = static_cast<char>(type);
    columnInfo->allowNull = (char)(allowNull ? 1 : 0);
    columnInfo->length = length;
    columnInfo->inBytes = inBytes;

    if ((type == VALUE_TYPE_VARCHAR && inBytes) || type == VALUE_TYPE_VARBINARY) {
        if (length == 0) {
            throwFatalLogicErrorStreamed("Zero length for object type " << valueToString((ValueType)type));
        }
        if (length < UNINLINEABLE_OBJECT_LENGTH) {
            /*
             * Inline the string if it is less then UNINLINEABLE_OBJECT_LENGTH bytes.
             */
            columnInfo->inlined = true;
            // One byte to store the size
            offset = static_cast<uint32_t>(length + SHORT_OBJECT_LENGTHLENGTH);
        } else {
            /*
             * Set the length to the size of a String pointer since it won't be inlined.
             */
            offset = static_cast<uint32_t>(NValue::getTupleStorageSize(type));
            columnInfo->inlined = false;
            setUninlinedObjectColumnInfoIndex(uninlinedObjectColumnIndex++, index);
        }
    } else if (type == VALUE_TYPE_VARCHAR) {
        if (length == 0) {
            throwFatalLogicErrorStreamed("Zero length for object type " << valueToString((ValueType)type));
        }
        if (length < UNINLINEABLE_CHARACTER_LENGTH) {
            /*
             * Inline the string if it is less then UNINLINEABLE_CHARACTER_LENGTH characters.
             */
            columnInfo->inlined = true;
            // One byte to store the size
            offset = static_cast<uint32_t>(length * 4 + SHORT_OBJECT_LENGTHLENGTH);
        } else {
            /*
             * Set the length to the size of a String pointer since it won't be inlined.
             */
            offset = static_cast<uint32_t>(NValue::getTupleStorageSize(type));
            columnInfo->inlined = false;
            setUninlinedObjectColumnInfoIndex(uninlinedObjectColumnIndex++, index);
        }
    } else {
        // All values are inlined if they aren't strings.
        columnInfo->inlined = true;
        // don't trust the planner since it can be avoided
        offset = static_cast<uint32_t>(NValue::getTupleStorageSize(type));
    }
    // make the column offsets right for all columns past this one
    int oldsize = columnLengthPrivate(index);
    ColumnInfo *nextColumnInfo = NULL;
    for (int i = index + 1; i <= m_columnCount; i++) {
        nextColumnInfo = getColumnInfo(i);
        nextColumnInfo->offset = static_cast<uint32_t>(nextColumnInfo->offset + offset - oldsize);
    }
    assert(index == 0 ? columnInfo->offset == 0 : true);
}