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 871cb090 supports automatic type conversion (#381)
871cb090 is described below
commit 871cb0903b8b04ad5f9e7f5e7ff1218e3618ff37
Author: Yukim1 <[email protected]>
AuthorDate: Mon Jan 13 12:03:26 2025 +0800
supports automatic type conversion (#381)
---
cpp/src/common/tablet.cc | 24 +++++++++++++++++++-----
cpp/src/common/tablet.h | 2 ++
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/cpp/src/common/tablet.cc b/cpp/src/common/tablet.cc
index fa5c2994..cfc4b574 100644
--- a/cpp/src/common/tablet.cc
+++ b/cpp/src/common/tablet.cc
@@ -85,6 +85,13 @@ int Tablet::add_timestamp(uint32_t row_index, int64_t
timestamp) {
return E_OK;
}
+template <typename T>
+void Tablet::process_val(uint32_t row_index, uint32_t schema_index, T val) {
+ T *column_values = (T *)value_matrix_[schema_index];
+ column_values[row_index] = val;
+ bitmaps_[schema_index].set(row_index); /* mark as non-null*/
+}
+
template <typename T>
int Tablet::add_value(uint32_t row_index, uint32_t schema_index, T val) {
int ret = common::E_OK;
@@ -93,12 +100,19 @@ 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);
- if (LIKELY(GetDataTypeFromTemplateType<T>() != schema.data_type_)) {
- ret = common::E_TYPE_NOT_MATCH;
+ if (UNLIKELY(GetDataTypeFromTemplateType<T>() != schema.data_type_)) {
+ if (GetDataTypeFromTemplateType<T>() == common::INT32 &&
+ schema.data_type_ == common::INT64) {
+ process_val(row_index, schema_index,
static_cast<int64_t>(val));
+ } else if (GetDataTypeFromTemplateType<T>() == common::FLOAT &&
+ schema.data_type_ == common::DOUBLE) {
+ process_val(row_index, schema_index, static_cast<double>(val));
+ } else {
+ ASSERT(false);
+ return E_TYPE_NOT_MATCH;
+ }
} else {
- T *column_values = (T *)value_matrix_[schema_index];
- column_values[row_index] = val;
- bitmaps_[schema_index].set(row_index); /* mark as non-null*/
+ process_val(row_index, schema_index, val);
}
}
return ret;
diff --git a/cpp/src/common/tablet.h b/cpp/src/common/tablet.h
index 55a686d6..12fbc1fd 100644
--- a/cpp/src/common/tablet.h
+++ b/cpp/src/common/tablet.h
@@ -108,6 +108,8 @@ class Tablet {
typedef std::map<std::string, int>::iterator SchemaMapIterator;
private:
+ template <typename T>
+ void process_val(uint32_t row_index, uint32_t schema_index, T val);
int max_row_num_;
std::string device_id_;
std::shared_ptr<std::vector<MeasurementSchema>> schema_vec_;