diff --git a/cpp/src/common/db_common.h b/cpp/src/common/db_common.h index 485a0c104..215abf3d4 100644 --- a/cpp/src/common/db_common.h +++ b/cpp/src/common/db_common.h @@ -142,40 +142,38 @@ FORCE_INLINE common::TSDataType GetDataTypeFromTemplateType() { } template -FORCE_INLINE std::unordered_set -GetDataTypesFromTemplateType() { - return {common::INVALID_DATATYPE}; +FORCE_INLINE bool TypeMatch(common::TSDataType dt) { + return dt == common::INVALID_DATATYPE; } template <> -FORCE_INLINE std::unordered_set -GetDataTypesFromTemplateType() { - return {common::BOOLEAN}; +FORCE_INLINE bool TypeMatch(common::TSDataType dt) { + return dt == common::BOOLEAN; } + template <> -FORCE_INLINE std::unordered_set -GetDataTypesFromTemplateType() { - return {common::INT32, common::DATE, common::INT64}; +FORCE_INLINE bool TypeMatch(common::TSDataType dt) { + return dt == common::INT32 || dt == common::DATE || dt == common::INT64; } + template <> -FORCE_INLINE std::unordered_set -GetDataTypesFromTemplateType() { - return {common::INT64, TIMESTAMP}; +FORCE_INLINE bool TypeMatch(common::TSDataType dt) { + return dt == common::INT64 || dt == common::TIMESTAMP; } + template <> -FORCE_INLINE std::unordered_set -GetDataTypesFromTemplateType() { - return {common::FLOAT, common::DOUBLE}; +FORCE_INLINE bool TypeMatch(common::TSDataType dt) { + return dt == common::FLOAT || dt == common::DOUBLE; } + template <> -FORCE_INLINE std::unordered_set -GetDataTypesFromTemplateType() { - return {common::DOUBLE}; +FORCE_INLINE bool TypeMatch(common::TSDataType dt) { + return dt == common::DOUBLE; } + template <> -FORCE_INLINE std::unordered_set -GetDataTypesFromTemplateType() { - return {common::STRING, common::TEXT, common::BLOB}; +FORCE_INLINE bool TypeMatch(common::TSDataType dt) { + return dt == common::STRING || dt == common::TEXT || dt == common::BLOB; } FORCE_INLINE size_t get_data_type_size(TSDataType data_type) { diff --git a/cpp/src/common/tablet.cc b/cpp/src/common/tablet.cc index 2a22d78d0..10489f67d 100644 --- a/cpp/src/common/tablet.cc +++ b/cpp/src/common/tablet.cc @@ -255,8 +255,7 @@ int Tablet::add_value(uint32_t row_index, uint32_t schema_index, T val) { ret = common::E_OUT_OF_RANGE; } else { const MeasurementSchema& schema = schema_vec_->at(schema_index); - auto dic = GetDataTypesFromTemplateType(); - if (dic.find(schema.data_type_) == dic.end()) { + if (UNLIKELY(!TypeMatch(schema.data_type_))) { return E_TYPE_NOT_MATCH; } process_val(row_index, schema_index, val); @@ -281,27 +280,6 @@ int Tablet::add_value(uint32_t row_index, uint32_t schema_index, std::tm val) { return ret; } -template <> -int Tablet::add_value(uint32_t row_index, uint32_t schema_index, - common::String val) { - if (err_code_ != E_OK) { - return err_code_; - } - int ret = common::E_OK; - if (UNLIKELY(schema_index >= schema_vec_->size())) { - ASSERT(false); - ret = common::E_OUT_OF_RANGE; - } else { - const MeasurementSchema& schema = schema_vec_->at(schema_index); - auto dic = GetDataTypesFromTemplateType(); - if (dic.find(schema.data_type_) == dic.end()) { - return E_TYPE_NOT_MATCH; - } - process_val(row_index, schema_index, val); - } - return ret; -} - template <> int Tablet::add_value(uint32_t row_index, uint32_t schema_index, const char* val) { @@ -340,6 +318,8 @@ template int Tablet::add_value(uint32_t row_index, uint32_t schema_index, float val); template int Tablet::add_value(uint32_t row_index, uint32_t schema_index, double val); +template int Tablet::add_value(uint32_t row_index, uint32_t schema_index, + String val); template int Tablet::add_value(uint32_t row_index, const std::string& measurement_name, bool val); diff --git a/cpp/src/writer/tsfile_writer.cc b/cpp/src/writer/tsfile_writer.cc index 1f7d954ce..2c2e46b97 100644 --- a/cpp/src/writer/tsfile_writer.cc +++ b/cpp/src/writer/tsfile_writer.cc @@ -863,6 +863,16 @@ TsFileWriter::split_tablet_by_device(const Tablet& tablet) { std::vector, int>> result; std::shared_ptr last_device_id = std::make_shared("last_device_id"); + if (tablet.id_column_indexes_.empty()) { + result.emplace_back(std::move(last_device_id), 0); + std::vector id_array; + id_array.push_back(new std::string(tablet.insert_target_name_)); + auto res = std::make_shared(id_array); + delete id_array[0]; + result.emplace_back(std::move(res), tablet.get_cur_row_size()); + return result; + } + for (uint32_t i = 0; i < tablet.get_cur_row_size(); i++) { std::shared_ptr cur_device_id(tablet.get_device_id(i)); if (*cur_device_id != *last_device_id) {