diff --git a/storage/rapid_engine/compress/algorithms.cpp b/storage/rapid_engine/compress/algorithms.cpp index ce52321d1..d45704fbe 100644 --- a/storage/rapid_engine/compress/algorithms.cpp +++ b/storage/rapid_engine/compress/algorithms.cpp @@ -153,6 +153,7 @@ std::string &lz4_compress::decompressString(std::string &compressed_str) { void CompressFactory::make_elements() { // important: the inserted index should same as its algo type value. m_factory.emplace_back(std::make_unique()); + m_factory.emplace_back(std::make_unique()); m_factory.emplace_back(std::make_unique()); m_factory.emplace_back(std::make_unique()); m_factory.emplace_back(std::make_unique()); diff --git a/storage/rapid_engine/compress/algorithms.h b/storage/rapid_engine/compress/algorithms.h index 6a6f9e132..6409bd2b2 100644 --- a/storage/rapid_engine/compress/algorithms.h +++ b/storage/rapid_engine/compress/algorithms.h @@ -37,7 +37,7 @@ namespace ShannonBase { namespace Compress { -enum compress_algos { NONE = 0, ZLIB, ZSTD, LZ4 }; +enum compress_algos { DEFAULT = 0, NONE, ZLIB, ZSTD, LZ4 }; class Compress_algorithm { public: diff --git a/storage/rapid_engine/compress/dictionary/dictionary.cpp b/storage/rapid_engine/compress/dictionary/dictionary.cpp index 0ae0b03db..951e78f34 100644 --- a/storage/rapid_engine/compress/dictionary/dictionary.cpp +++ b/storage/rapid_engine/compress/dictionary/dictionary.cpp @@ -91,32 +91,9 @@ uint32 Dictionary::store(const uchar *str, size_t len, Encoding_type type) { } uint32 Dictionary::get(uint64 strid, String &ret_val) { - compress_algos alg [[maybe_unused]]{compress_algos::NONE}; - switch (m_encoding_type) { - case Encoding_type::SORTED: - alg = compress_algos::ZSTD; - break; - case Encoding_type::VARLEN: - alg = compress_algos::LZ4; - break; - case Encoding_type::NONE: - alg = compress_algos::NONE; - break; - default: - break; - } - - { - std::scoped_lock lk(m_content_mtx); - auto id_pos = m_id2content.find(strid); - if (id_pos != m_id2content.end()) { - auto val_str = id_pos->second; - String strs(val_str.c_str(), val_str.length(), ret_val.charset()); - copy_if_not_alloced(&ret_val, &strs, strs.length()); - } else - return 0; - } - + auto compressed_str = reinterpret_cast(get(strid)); + String strs(compressed_str, strlen(compressed_str), ret_val.charset()); + copy_if_not_alloced(&ret_val, &strs, strs.length()); return 0; } @@ -139,8 +116,13 @@ uchar *Dictionary::get(uint64 strid) { { std::scoped_lock lk(m_content_mtx); auto id_pos = m_id2content.find(strid); - return (id_pos != m_id2content.end()) ? (uchar *)(id_pos->second.c_str()) : nullptr; + if (id_pos != m_id2content.end()) { + auto compressed_str = id_pos->second; + auto ret_strp = CompressFactory::get_instance(alg)->decompressString(compressed_str).c_str(); + return reinterpret_cast(const_cast(ret_strp)); + } } + return nullptr; } diff --git a/storage/rapid_engine/imcs/data_table.cpp b/storage/rapid_engine/imcs/data_table.cpp index a91f1c133..ea198a753 100644 --- a/storage/rapid_engine/imcs/data_table.cpp +++ b/storage/rapid_engine/imcs/data_table.cpp @@ -164,12 +164,12 @@ int DataTable::next(uchar *buf) { source_fld->set_notnull(); auto data_ptr = cu->chunk(current_chunk)->base() + offset_in_chunk * normalized_length; if (is_text_value) { - uint32 str_id = *(uint32 *)data_ptr; - auto str_ptr = cu->header()->m_local_dict->get(str_id); + uint32 str_id = *reinterpret_cast(data_ptr); + auto str_ptr = reinterpret_cast(cu->header()->m_local_dict->get(str_id)); Utils::Util::is_blob(cu->header()->m_type) - ? (down_cast(source_fld)->set_ptr(strlen((char *)str_ptr), str_ptr), 0) + ? down_cast(source_fld)->store(str_ptr, strlen(str_ptr), source_fld->charset()) : (Utils::Util::is_varstring(cu->header()->m_source_fld->type()) - ? source_fld->store(reinterpret_cast(str_ptr), strlen((char *)str_ptr), source_fld->charset()) + ? source_fld->store(reinterpret_cast(str_ptr), strlen(str_ptr), source_fld->charset()) : source_fld->store(reinterpret_cast(str_ptr), cu->pack_length(), source_fld->charset())); } else source_fld->pack(const_cast(source_fld->data_ptr()), data_ptr, normalized_length);