This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/tsfile.git


The following commit(s) were added to refs/heads/develop by this push:
     new 26ecec87 Use direct comparison to check data type consistency during 
Tablet.addValue (#678)
26ecec87 is described below

commit 26ecec875c47bc9e0a5f4aa00b3e9cd237283f7a
Author: Colin Lee <[email protected]>
AuthorDate: Fri Dec 26 09:52:24 2025 +0800

    Use direct comparison to check data type consistency during Tablet.addValue 
(#678)
    
    * refine writeing.
    
    * tmp code.
---
 cpp/src/common/db_common.h      | 40 +++++++++++++++++++---------------------
 cpp/src/common/tablet.cc        | 26 +++-----------------------
 cpp/src/writer/tsfile_writer.cc | 10 ++++++++++
 3 files changed, 32 insertions(+), 44 deletions(-)

diff --git a/cpp/src/common/db_common.h b/cpp/src/common/db_common.h
index 485a0c10..215abf3d 100644
--- a/cpp/src/common/db_common.h
+++ b/cpp/src/common/db_common.h
@@ -142,40 +142,38 @@ FORCE_INLINE common::TSDataType 
GetDataTypeFromTemplateType<common::String>() {
 }
 
 template <typename T>
-FORCE_INLINE std::unordered_set<common::TSDataType>
-GetDataTypesFromTemplateType() {
-    return {common::INVALID_DATATYPE};
+FORCE_INLINE bool TypeMatch(common::TSDataType dt) {
+    return dt == common::INVALID_DATATYPE;
 }
 
 template <>
-FORCE_INLINE std::unordered_set<common::TSDataType>
-GetDataTypesFromTemplateType<bool>() {
-    return {common::BOOLEAN};
+FORCE_INLINE bool TypeMatch<bool>(common::TSDataType dt) {
+    return dt == common::BOOLEAN;
 }
+
 template <>
-FORCE_INLINE std::unordered_set<common::TSDataType>
-GetDataTypesFromTemplateType<int32_t>() {
-    return {common::INT32, common::DATE, common::INT64};
+FORCE_INLINE bool TypeMatch<int32_t>(common::TSDataType dt) {
+    return dt == common::INT32 || dt == common::DATE || dt == common::INT64;
 }
+
 template <>
-FORCE_INLINE std::unordered_set<common::TSDataType>
-GetDataTypesFromTemplateType<int64_t>() {
-    return {common::INT64, TIMESTAMP};
+FORCE_INLINE bool TypeMatch<int64_t>(common::TSDataType dt) {
+    return dt == common::INT64 || dt == common::TIMESTAMP;
 }
+
 template <>
-FORCE_INLINE std::unordered_set<common::TSDataType>
-GetDataTypesFromTemplateType<float>() {
-    return {common::FLOAT, common::DOUBLE};
+FORCE_INLINE bool TypeMatch<float>(common::TSDataType dt) {
+    return dt == common::FLOAT || dt == common::DOUBLE;
 }
+
 template <>
-FORCE_INLINE std::unordered_set<common::TSDataType>
-GetDataTypesFromTemplateType<double>() {
-    return {common::DOUBLE};
+FORCE_INLINE bool TypeMatch<double>(common::TSDataType dt) {
+    return dt == common::DOUBLE;
 }
+
 template <>
-FORCE_INLINE std::unordered_set<common::TSDataType>
-GetDataTypesFromTemplateType<common::String>() {
-    return {common::STRING, common::TEXT, common::BLOB};
+FORCE_INLINE bool TypeMatch<common::String>(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 2a22d78d..10489f67 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<T>();
-        if (dic.find(schema.data_type_) == dic.end()) {
+        if (UNLIKELY(!TypeMatch<T>(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<common::String>();
-        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 1f7d954c..2c2e46b9 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<std::pair<std::shared_ptr<IDeviceID>, int>> result;
     std::shared_ptr<IDeviceID> last_device_id =
         std::make_shared<StringArrayDeviceID>("last_device_id");
+    if (tablet.id_column_indexes_.empty()) {
+        result.emplace_back(std::move(last_device_id), 0);
+        std::vector<std::string*> id_array;
+        id_array.push_back(new std::string(tablet.insert_target_name_));
+        auto res = std::make_shared<StringArrayDeviceID>(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<IDeviceID> cur_device_id(tablet.get_device_id(i));
         if (*cur_device_id != *last_device_id) {

Reply via email to