From 260849d1b13b38b3bcbba378157ca3c683ed017c Mon Sep 17 00:00:00 2001 From: ColinLee Date: Fri, 20 Nov 2026 10:57:04 +0800 Subject: [PATCH] refactor(cpp): remove unused TsBlock helpers --- cpp/src/common/tsblock/tsblock.cc | 178 ------------------------------ cpp/src/common/tsblock/tsblock.h | 13 --- 2 files changed, 191 deletions(-) diff --git a/cpp/src/common/tsblock/tsblock.cc b/cpp/src/common/tsblock/tsblock.cc index fd29f9f07..aa3e2c949 100644 --- a/cpp/src/common/tsblock/tsblock.cc +++ b/cpp/src/common/tsblock/tsblock.cc @@ -18,14 +18,11 @@ */ #include "tsblock.h" -#include #include namespace common { int TsBlock::init() { - // todo: The current version select_list_ is useless, so it is not - // initialized int ret = 0; uint32_t row_size = tuple_desc_->get_single_row_len(&ret); if (ret != 0) { @@ -68,157 +65,6 @@ int TsBlock::build_vector(common::TSDataType type, uint32_t row_count) { return ret; } -void TsBlock::write_data(ByteStream* __restrict byte_stream, - char* __restrict val, uint32_t len, bool has_null, - TSDataType type) { - std::string strval; - switch (type) { - case common::INT64: { - int64_t ival; - std::memcpy(&ival, val, sizeof(ival)); - strval = std::to_string(ival); - break; - } - case common::INT32: { - int32_t ival; - std::memcpy(&ival, val, sizeof(ival)); - strval = std::to_string(ival); - break; - } - case common::FLOAT: { - float ival; - std::memcpy(&ival, val, sizeof(ival)); - strval = std::to_string(ival); - break; - } - case common::DOUBLE: { - double ival; - std::memcpy(&ival, val, sizeof(ival)); - strval = std::to_string(ival); - break; - } - case common::BOOLEAN: { - bool ival; - std::memcpy(&ival, val, sizeof(ival)); - if (ival) { - strval = "true"; - } else { - strval = "false"; - } - break; - } - case common::TEXT: { - if (LIKELY(!has_null)) { - byte_stream->write_buf(val, len); - } else { - byte_stream->write_buf("null", 4); - } - byte_stream->write_buf(",\n", 2); - return; - } - default: { - // log_err("write_data unknown type"); - } - } - if (LIKELY(!has_null)) { - byte_stream->write_buf(const_cast(strval.c_str()), - strval.length()); - } else { - byte_stream->write_buf("null", 4); - } -} - -void TsBlock::tsblock_to_json(ByteStream* byte_stream) { - // 1. append start tag - byte_stream->write_buf("{\n", 2); - - // 2. append output columns to bytestream - int column_count = tuple_desc_->get_column_count(); - // 2.1 append header - byte_stream->write_buf(" \"expressions\": [\n", 19); - // 2.2 append column names - for (int i = 1; i < column_count; ++i) { - std::string name = tuple_desc_->get_column_name(i); - byte_stream->write_buf(" ", 4); - byte_stream->write_buf("\"", 1); - byte_stream->write_buf(name.c_str(), name.length()); - byte_stream->write_buf("\"", 1); - if (i == column_count - 1) { - byte_stream->write_buf("\n", 1); - } else { - byte_stream->write_buf(",\n", 2); - } - } - byte_stream->write_buf(" ],\n", 5); - - // 3. append column_names - byte_stream->write_buf(" \"column_names\": null,\n", 24); - - // 4. append time value - byte_stream->write_buf(" \"timestamps\": [\n", 18); - ColIterator time_iter(0, this); - bool is_first = true; - while (!time_iter.end()) { - uint32_t ilen; - byte_stream->write_buf(" ", 4); - char* val = time_iter.read(&ilen); - if (!is_first) { - byte_stream->write_buf(",\n", 2); - } - is_first = false; - write_data(byte_stream, val, ilen, false, INT64); - time_iter.next(); - } - byte_stream->write_buf(" ],\n", 5); - - // 5. append user values - byte_stream->write_buf(" \"values\": [\n", 14); - for (int i = 1; i < column_count; ++i) { - byte_stream->write_buf(" [\n", 6); - - ColIterator value_iter(i, this); - bool has_null = value_iter.has_null(); - if (LIKELY(!has_null)) { - bool is_first = true; // cppcheck-suppress shadowVariable - while (!value_iter.end()) { - uint32_t ilen = 0; - byte_stream->write_buf(" ", 6); - char* val = value_iter.read(&ilen); - if (!is_first) { - byte_stream->write_buf(",\n", 2); - } - is_first = false; - write_data(byte_stream, val, ilen, false, - tuple_desc_->get_column_type(i)); - value_iter.next(); - } - } else { - while (!value_iter.end()) { - bool inull; - uint32_t ilen = 0; - byte_stream->write_buf(" ", 6); - char* val = value_iter.read(&ilen, &inull); - if (!is_first) { - byte_stream->write_buf(",\n", 2); - } - is_first = false; - write_data(byte_stream, val, ilen, inull, - tuple_desc_->get_column_type(i)); - value_iter.next(); - } - } - if (i == column_count - 1) { - byte_stream->write_buf(" ]\n", 6); - } else { - byte_stream->write_buf(" ],\n", 7); - } - } - byte_stream->write_buf(" ]\n", 4); - - // 6. end - byte_stream->write_buf("}\n", 2); -} - #ifdef DEBUG std::string TsBlock::debug_string() { std::stringstream out; @@ -295,28 +141,4 @@ std::string RowIterator::debug_string() { return out.str(); } #endif -// TODO use memcpy in vector instead of using iter/appender -int merge_tsblock_by_row(TsBlock* sea, TsBlock* river) { - int ret = E_OK; - TupleDesc* sea_tuple_desc = sea->get_tuple_desc(); - TupleDesc* river_tupe_desc = river->get_tuple_desc(); - if (!sea_tuple_desc->equal_to(*river_tupe_desc)) { - ret = E_NOT_MATCH; - } else { - RowAppender sea_appender(sea); - RowIterator river_iter(river); - while (!river_iter.end()) { - sea_appender.add_row(); - for (uint32_t c = 0; c < sea_tuple_desc->get_column_count(); c++) { - uint32_t len = 0; - bool null = false; - char* val = river_iter.read(c, &len, &null); - sea_appender.append(c, val, len); - } - river_iter.next(); - } - } - return ret; -} - } // namespace common diff --git a/cpp/src/common/tsblock/tsblock.h b/cpp/src/common/tsblock/tsblock.h index f0ed388c0..230899b19 100644 --- a/cpp/src/common/tsblock/tsblock.h +++ b/cpp/src/common/tsblock/tsblock.h @@ -23,7 +23,6 @@ #include -#include "common/allocator/byte_stream.h" #include "common/container/byte_buffer.h" #include "common/global.h" #include "common/logger/elog.h" @@ -72,12 +71,6 @@ class TsBlock { FORCE_INLINE uint32_t get_max_row_count() const { return max_row_count_; } - FORCE_INLINE uint32_t get_capacity() const { return capacity_; } - - FORCE_INLINE void update_capacity(uint32_t extend_size) { - capacity_ += extend_size; - } - FORCE_INLINE void fill_trailling_nulls() { for (uint32_t i = 0; i < get_column_count(); ++i) { for (uint32_t j = vectors_[i]->get_row_num(); j < row_count_; ++j) { @@ -109,21 +102,17 @@ class TsBlock { } int init(); - void tsblock_to_json(ByteStream* byte_stream); std::string debug_string(); private: int build_vector(common::TSDataType type, uint32_t row_count); - void write_data(ByteStream* __restrict byte_stream, char* __restrict val, - uint32_t len, bool has_null, TSDataType type); private: uint32_t capacity_; // maximum memory capacity uint32_t row_count_; // real row count uint32_t max_row_count_; - common::BitMap select_list_; TupleDesc* tuple_desc_; std::vector vectors_; }; @@ -402,7 +391,5 @@ class ColIterator { Vector* vec_; }; -int merge_tsblock_by_row(TsBlock* sea, TsBlock* river); - } // end namespace common #endif // COMMON_TSBLOCK_TSBLOCK_H