From 7d96ea6987d6ee7b2d4385fb267f161e06e56e7d Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Fri, 13 Dec 2024 15:42:38 +0800 Subject: [PATCH] cutoff string data for var_char Committed-by: xiaolei.zl from Dev container --- flex/utils/property/column.cc | 7 +++++-- flex/utils/property/column.h | 13 +++++++++---- flex/utils/property/types.h | 5 +++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/flex/utils/property/column.cc b/flex/utils/property/column.cc index a2581be4caa7..cb29b9c8c9fc 100644 --- a/flex/utils/property/column.cc +++ b/flex/utils/property/column.cc @@ -169,11 +169,14 @@ std::shared_ptr CreateColumn( return std::make_shared(strategy); } else if (type == PropertyType::kStringMap) { return std::make_shared(strategy); - } else if (type == PropertyType::kStringView) { - return std::make_shared(strategy); } else if (type.type_enum == impl::PropertyTypeImpl::kVarChar) { + // We must check is varchar first, because in implementation of + // PropertyType::operator==(const PropertyType& other), we string_view is + // equal to varchar. return std::make_shared( strategy, type.additional_type_info.max_length); + } else if (type == PropertyType::kStringView) { + return std::make_shared(strategy); } else if (type.type_enum == impl::PropertyTypeImpl::kRecordView) { return std::make_shared(sub_types); } else { diff --git a/flex/utils/property/column.h b/flex/utils/property/column.h index a556857e77cc..393ba02f7bd2 100644 --- a/flex/utils/property/column.h +++ b/flex/utils/property/column.h @@ -499,12 +499,17 @@ class TypedColumn : public ColumnBase { PropertyType type() const override { return PropertyType::Varchar(width_); } void set_value(size_t idx, const std::string_view& val) { + auto copied_val = val; + if (copied_val.size() >= width_) { + LOG(WARNING) << "String length exceeds the maximum length: " << width_; + copied_val = copied_val.substr(0, width_); + } if (idx >= basic_size_ && idx < basic_size_ + extra_size_) { - size_t offset = pos_.fetch_add(val.size()); - extra_buffer_.set(idx - basic_size_, offset, val); + size_t offset = pos_.fetch_add(copied_val.size()); + extra_buffer_.set(idx - basic_size_, offset, copied_val); } else if (idx < basic_size_) { - size_t offset = basic_pos_.fetch_add(val.size()); - basic_buffer_.set(idx, offset, val); + size_t offset = basic_pos_.fetch_add(copied_val.size()); + basic_buffer_.set(idx, offset, copied_val); } else { LOG(FATAL) << "Index out of range"; } diff --git a/flex/utils/property/types.h b/flex/utils/property/types.h index ad7eb1f36f5a..ae82c000d210 100644 --- a/flex/utils/property/types.h +++ b/flex/utils/property/types.h @@ -1408,9 +1408,10 @@ struct convert { if (config["string"]["var_char"]["max_length"]) { property_type = gs::PropertyType::Varchar( config["string"]["var_char"]["max_length"].as()); + } else { + property_type = gs::PropertyType::Varchar( + gs::PropertyType::STRING_DEFAULT_MAX_LENGTH); } - property_type = gs::PropertyType::Varchar( - gs::PropertyType::STRING_DEFAULT_MAX_LENGTH); } else { LOG(ERROR) << "Unrecognized string type"; }