* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
* Description: Row buffer Header
*/
#include "rowdata_marshaller.h"
void SerializeLongIntoRowData(vec::BaseVector *baseVector, int32_t rowIdx, BinaryRowData *result, int32_t pos)
{
if (baseVector->IsNull(rowIdx)) {
result->setNullAt(pos);
} else {
result->setLong(pos, reinterpret_cast<vec::Vector<int64_t>*>(baseVector)->GetValue(rowIdx));
}
}
void SerializeIntIntoRowData(vec::BaseVector *baseVector, int32_t rowIdx, BinaryRowData *result, int32_t pos)
{
if (baseVector->IsNull(rowIdx)) {
result->setNullAt(pos);
} else {
result->setInt(pos, reinterpret_cast<vec::Vector<int32_t>*>(baseVector)->GetValue(rowIdx));
}
}
void SerializeBooleanIntoRowData(vec::BaseVector *baseVector, int32_t rowIdx, BinaryRowData *result, int32_t pos)
{
if (baseVector->IsNull(rowIdx)) {
result->setNullAt(pos);
} else {
result->setBool(pos, reinterpret_cast<vec::Vector<bool>*>(baseVector)->GetValue(rowIdx));
}
}
void SerializeDecimal128IntoRowData(vec::BaseVector *baseVector, int32_t rowIdx, BinaryRowData *result, int32_t pos) {
if (baseVector->IsNull(rowIdx)) {
result->setNullAt(pos);
} else {
auto value = reinterpret_cast<vec::Vector<Decimal128>*>(baseVector)->GetValue(rowIdx);
result->setDecimal128(pos, value.LowBits(), value.HighBits());
}
}
void SerializeVarcharIntoRowData(vec::BaseVector *baseVector, int32_t rowIdx, BinaryRowData *result, int32_t pos)
{
if (baseVector->IsNull(rowIdx)) {
result->setNullAt(pos);
} else if (baseVector->GetEncoding() == omniruntime::vec::OMNI_FLAT) {
auto casted = reinterpret_cast<omniruntime::vec::Vector
<omniruntime::vec::LargeStringContainer<std::string_view>> *>(baseVector);
auto val = casted->GetValue(rowIdx);
result->setStringView(pos, val);
} else if (baseVector->GetEncoding() == omniruntime::vec::OMNI_DICTIONARY) {
auto casted = reinterpret_cast<omniruntime::vec::Vector<omniruntime::vec::DictionaryContainer<
std::string_view, omniruntime::vec::LargeStringContainer>> *>(baseVector);
auto val = casted->GetValue(rowIdx);
result->setStringView(pos, val);
} else {
throw std::runtime_error("encoding not supported");
}
}
void DeserializeIntFromRowData(vec::BaseVector *baseVector, int32_t rowIdx, BinaryRowData *input, int32_t pos)
{
if (input->isNullAt(pos)) {
baseVector->SetNull(rowIdx);
} else {
reinterpret_cast<vec::Vector<int32_t> *>(baseVector)->SetValue(rowIdx, *input->getInt(pos));
}
}
void DeserializeLongFromRowData(vec::BaseVector *baseVector, int32_t rowIdx, BinaryRowData *input, int32_t pos)
{
if (input->isNullAt(pos)) {
baseVector->SetNull(rowIdx);
} else {
reinterpret_cast<vec::Vector<int64_t>*>(baseVector)->SetValue(rowIdx, *input->getLong(pos));
}
}
void DeserializeVarcharFromRowData(vec::BaseVector *baseVector, int32_t rowIdx, BinaryRowData *input, int32_t pos)
{
if (input->isNullAt(pos)) {
baseVector->SetNull(rowIdx);
} else if (baseVector->GetEncoding() == omniruntime::vec::OMNI_FLAT) {
auto casted = reinterpret_cast<omniruntime::vec::Vector
<omniruntime::vec::LargeStringContainer<std::string_view>> *>(baseVector);
std::string_view sv = input->getStringView(pos);
casted->SetValue(rowIdx, sv);
} else if (baseVector->GetEncoding() == omniruntime::vec::OMNI_DICTIONARY) {
auto casted = reinterpret_cast<omniruntime::vec::Vector<omniruntime::vec::DictionaryContainer<
std::string_view, omniruntime::vec::LargeStringContainer>> *>(baseVector);
std::string_view sv = input->getStringView(pos);
casted->SetValue(rowIdx, sv);
} else {
throw std::runtime_error("encoding not supported");
}
}
std::vector<VBToRowSerializer> rowSerializerCenter = {
nullptr,
SerializeIntIntoRowData,
SerializeLongIntoRowData,
nullptr,
SerializeBooleanIntoRowData,
nullptr,
SerializeLongIntoRowData,
SerializeDecimal128IntoRowData,
SerializeIntIntoRowData,
SerializeLongIntoRowData,
SerializeIntIntoRowData,
SerializeLongIntoRowData,
SerializeLongIntoRowData,
nullptr,
nullptr,
SerializeVarcharIntoRowData,
SerializeVarcharIntoRowData,
nullptr
};
std::vector<RowToVBDeSerializer> rowDeserializerCenter = {
nullptr,
DeserializeIntFromRowData,
DeserializeLongFromRowData,
nullptr,
nullptr,
nullptr,
DeserializeLongFromRowData,
nullptr,
DeserializeIntFromRowData,
DeserializeLongFromRowData,
DeserializeIntFromRowData,
DeserializeLongFromRowData,
DeserializeLongFromRowData,
nullptr,
nullptr,
DeserializeVarcharFromRowData,
DeserializeVarcharFromRowData,
nullptr
};