You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tsfile.apache.org by co...@apache.org on 2025/12/25 09:42:30 UTC

(tsfile) branch refine_write created (now 4bf7b0b0)

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

colinlee pushed a change to branch refine_write
in repository https://gitbox.apache.org/repos/asf/tsfile.git


      at 4bf7b0b0 refine writeing.

This branch includes the following new commits:

     new 4bf7b0b0 refine writeing.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(tsfile) 01/01: refine writeing.

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4bf7b0b0bd827cf0ca1accc1ee9a69818b6534c2
Author: colin <sh...@163.com>
AuthorDate: Thu Dec 25 17:36:00 2025 +0800

    refine writeing.
---
 cpp/src/common/db_common.h      | 40 +++++++++++++++++++---------------------
 cpp/src/common/tablet.cc        | 24 +-----------------------
 cpp/src/writer/tsfile_writer.cc |  9 +++++++++
 3 files changed, 29 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..84225473 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) {
diff --git a/cpp/src/writer/tsfile_writer.cc b/cpp/src/writer/tsfile_writer.cc
index 1f7d954c..3e92dff6 100644
--- a/cpp/src/writer/tsfile_writer.cc
+++ b/cpp/src/writer/tsfile_writer.cc
@@ -863,6 +863,15 @@ 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);
+        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) {