yiguolei commented on code in PR #58905:
URL: https://github.com/apache/doris/pull/58905#discussion_r2610132829


##########
be/src/olap/delete_handler.cpp:
##########
@@ -43,6 +51,298 @@ using ::google::protobuf::RepeatedPtrField;
 
 namespace doris {
 
+template <PrimitiveType PType>
+typename PrimitiveTypeTraits<PType>::CppType convert(const 
vectorized::DataTypePtr& data_type,
+                                                     const std::string& str,
+                                                     vectorized::Arena& arena) 
{
+    typename PrimitiveTypeTraits<PType>::CppType res;
+    if constexpr (PType == TYPE_TINYINT || PType == TYPE_SMALLINT || PType == 
TYPE_INT ||
+                  PType == TYPE_BIGINT || PType == TYPE_LARGEINT) {
+        vectorized::CastParameters parameters;
+        if (!vectorized::CastToInt::from_string({str.data(), str.size()}, res, 
parameters)) {
+            throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "invalid {} string. str={}", 
type_to_string(data_type->get_primitive_type()),
+                    str));
+        }
+        return res;
+    }
+    if constexpr (PType == TYPE_FLOAT || PType == TYPE_DOUBLE) {
+        vectorized::CastParameters parameters;
+        if (!vectorized::CastToFloat::from_string({str.data(), str.size()}, 
res, parameters)) {
+            throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "invalid {} string. str={}", 
type_to_string(data_type->get_primitive_type()),
+                    str));
+        }
+        return res;
+    }
+    if constexpr (PType == TYPE_DATE) {
+        vectorized::CastParameters parameters;
+        if (!vectorized::CastToDateOrDatetime::from_string<false>({str.data(), 
str.size()}, res,
+                                                                  nullptr, 
parameters)) {
+            throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "invalid {} string. str={}", 
type_to_string(data_type->get_primitive_type()),
+                    str));
+        }
+        return res;
+    }
+    if constexpr (PType == TYPE_DATETIME) {
+        vectorized::CastParameters parameters;
+        if (!vectorized::CastToDateOrDatetime::from_string<true>({str.data(), 
str.size()}, res,
+                                                                 nullptr, 
parameters)) {
+            throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "invalid {} string. str={}", 
type_to_string(data_type->get_primitive_type()),
+                    str));
+        }
+        return res;
+    }
+    if constexpr (PType == TYPE_DATEV2) {
+        vectorized::CastParameters parameters;
+        if (!vectorized::CastToDateV2::from_string({str.data(), str.size()}, 
res, nullptr,
+                                                   parameters)) {
+            throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "invalid {} string. str={}", 
type_to_string(data_type->get_primitive_type()),
+                    str));
+        }
+        return res;
+    }
+    if constexpr (PType == TYPE_DATETIMEV2) {
+        vectorized::CastParameters parameters;
+        if (!vectorized::CastToDatetimeV2::from_string({str.data(), 
str.size()}, res, nullptr,
+                                                       data_type->get_scale(), 
parameters)) {
+            throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "invalid {} string. str={}", 
type_to_string(data_type->get_primitive_type()),
+                    str));
+        }
+        return res;
+    }
+    if constexpr (PType == TYPE_CHAR) {
+        size_t target = assert_cast<const vectorized::DataTypeString*>(
+                                vectorized::remove_nullable(data_type).get())
+                                ->len();
+        res = {str.data(), str.size()};
+        if (target > str.size()) {
+            char* buffer = arena.alloc(target);
+            memset(buffer, 0, target);
+            memcpy(buffer, str.data(), str.size());
+            res = {buffer, target};
+        }
+        return res;
+    }
+    if constexpr (is_string_type(PType)) {

Review Comment:
   这里不要使用is string type,容易跟118 行混,直接写是varchar 或者string



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to