Beispiel #1
0
void Table::loadTuplesFromNoHeader(SerializeInputBE &serialize_io,
                                   Pool *stringPool,
                                   ReferenceSerializeOutput *uniqueViolationOutput,
                                   bool shouldDRStreamRow) {
    int tupleCount = serialize_io.readInt();
    assert(tupleCount >= 0);

    TableTuple target(m_schema);

    //Reserve space for a length prefix for rows that violate unique constraints
    //If there is no output supplied it will just throw
    size_t lengthPosition = 0;
    int32_t serializedTupleCount = 0;
    size_t tupleCountPosition = 0;
    if (uniqueViolationOutput != NULL) {
        lengthPosition = uniqueViolationOutput->reserveBytes(4);
    }
    for (int i = 0; i < tupleCount; ++i) {
        nextFreeTuple(&target);
        target.setActiveTrue();
        target.setDirtyFalse();
        target.setPendingDeleteFalse();
        target.setPendingDeleteOnUndoReleaseFalse();

        target.deserializeFrom(serialize_io, stringPool);

        processLoadedTuple(target, uniqueViolationOutput, serializedTupleCount, tupleCountPosition, shouldDRStreamRow);
    }

    //If unique constraints are being handled, write the length/size of constraints that occured
    if (uniqueViolationOutput != NULL) {
        if (serializedTupleCount == 0) {
            uniqueViolationOutput->writeIntAt(lengthPosition, 0);
        } else {
            uniqueViolationOutput->writeIntAt(lengthPosition,
                                              static_cast<int32_t>(uniqueViolationOutput->position() - lengthPosition - sizeof(int32_t)));
            uniqueViolationOutput->writeIntAt(tupleCountPosition,
                                              serializedTupleCount);
        }
    }
}
Beispiel #2
0
void Tuple::DeserializeWithHeaderFrom(SerializeInputBE &input) {
  PL_ASSERT(tuple_schema);
  PL_ASSERT(tuple_data);

  input.ReadInt();  // Read in the tuple size, discard

  const int column_count = tuple_schema->GetColumnCount();

  for (int column_itr = 0; column_itr < column_count; column_itr++) {
    const ValueType type = tuple_schema->GetType(column_itr);

    const bool is_inlined = tuple_schema->IsInlined(column_itr);
    char *data_ptr = GetDataPtr(column_itr);
    const int32_t column_length = tuple_schema->GetLength(column_itr);

    // TODO: Not sure about arguments
    const bool is_in_bytes = false;
    Value::DeserializeFrom(input, NULL, data_ptr, type, is_inlined,
                           column_length, is_in_bytes);
  }
}
Beispiel #3
0
void Tuple::DeserializeFrom(SerializeInputBE &input, VarlenPool *dataPool) {
  PL_ASSERT(tuple_schema);
  PL_ASSERT(tuple_data);

  input.ReadInt();
  const int column_count = tuple_schema->GetColumnCount();

  for (int column_itr = 0; column_itr < column_count; column_itr++) {
    const ValueType type = tuple_schema->GetType(column_itr);

    /**
     * DeserializeFrom is only called when we serialize/deserialize tables.
     * The serialization format for Strings/Objects in a serialized table
     * happens to have the same in memory representation as the Strings/Objects
     * in a Tuple. The goal here is to wrap the serialized representation of
     * the value in an Value and then serialize that into the tuple from the
     * Value. This makes it possible to push more value specific functionality
     * out of Tuple. The memory allocation will be performed when serializing
     * to tuple storage.
     */
    const bool is_inlined = tuple_schema->IsInlined(column_itr);
    int32_t column_length;
    char *data_ptr = GetDataPtr(column_itr);

    if (is_inlined) {
      column_length = tuple_schema->GetLength(column_itr);
    } else {
      column_length = tuple_schema->GetVariableLength(column_itr);
    }

    // TODO: Not sure about arguments
    const bool is_in_bytes = false;
    Value::DeserializeFrom(input, dataPool, data_ptr, type, is_inlined,
                           column_length, is_in_bytes);
  }
}
Beispiel #4
0
void Table::loadTuplesFrom(SerializeInputBE &serialInput,
                           Pool *stringPool,
                           ReferenceSerializeOutput *uniqueViolationOutput,
                           bool shouldDRStreamRow) {
    /*
     * directly receives a VoltTable buffer.
     * [00 01]   [02 03]   [04 .. 0x]
     * rowstart  colcount  colcount * 1 byte (column types)
     *
     * [0x+1 .. 0y]
     * colcount * strings (column names)
     *
     * [0y+1 0y+2 0y+3 0y+4]
     * rowcount
     *
     * [0y+5 .. end]
     * rowdata
     */

    // todo: just skip ahead to this position
    serialInput.readInt(); // rowstart

    serialInput.readByte();

    int16_t colcount = serialInput.readShort();
    assert(colcount >= 0);

    // Store the following information so that we can provide them to the user
    // on failure
    ValueType types[colcount];
    boost::scoped_array<std::string> names(new std::string[colcount]);

    // skip the column types
    for (int i = 0; i < colcount; ++i) {
        types[i] = (ValueType) serialInput.readEnumInSingleByte();
    }

    // skip the column names
    for (int i = 0; i < colcount; ++i) {
        names[i] = serialInput.readTextString();
    }

    // Check if the column count matches what the temp table is expecting
    int16_t expectedColumnCount = static_cast<int16_t>(m_schema->columnCount() + m_schema->hiddenColumnCount());
    if (colcount != expectedColumnCount) {
        std::stringstream message(std::stringstream::in
                                  | std::stringstream::out);
        message << "Column count mismatch. Expecting "
                << expectedColumnCount
                << ", but " << colcount << " given" << std::endl;
        message << "Expecting the following columns:" << std::endl;
        message << debug() << std::endl;
        message << "The following columns are given:" << std::endl;
        for (int i = 0; i < colcount; i++) {
            message << "column " << i << ": " << names[i]
                    << ", type = " << getTypeName(types[i]) << std::endl;
        }
        throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION,
                                      message.str().c_str());
    }

    loadTuplesFromNoHeader(serialInput, stringPool, uniqueViolationOutput, shouldDRStreamRow);
}