Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions cpp/src/common/db_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 3 additions & 23 deletions cpp/src/common/tablet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions cpp/src/writer/tsfile_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading